Skip to content
Snippets Groups Projects
Commit 0138c96a authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Add test to ensure that fwd decls are sorted

parent 0436609f
No related branches found
No related tags found
1 merge request!2193Add test to ensure that fwd decls are sorted
Pipeline #122247 passed
...@@ -98,6 +98,14 @@ def check_block(fn, t, name, errs): ...@@ -98,6 +98,14 @@ def check_block(fn, t, name, errs):
elif m.group(5) != '\n': elif m.group(5) != '\n':
errs.append(f"more than one blank line below {name} block in file {fn}") errs.append(f"more than one blank line below {name} block in file {fn}")
def check_fwd_decl_sorted(fn, t, errs):
for m in re.finditer(r'((class|struct) (\w+);([ ]*//.*)?\n)+', t):
decls_txt = m.group(0)
decls_arr = decls_txt.rstrip('\n').split('\n')
if decls_arr != sorted(decls_arr):
errs.append(f"forward declarations not sorted in file {fn}")
return
#################################################################################################### ####################################################################################################
# main # main
#################################################################################################### ####################################################################################################
...@@ -114,11 +122,14 @@ if __name__ == "__main__": ...@@ -114,11 +122,14 @@ if __name__ == "__main__":
# tests on each file: # tests on each file:
for fn in allfiles: for fn in allfiles:
stem, suffix = split_fname(fn)
with open(fn, 'r') as fd: with open(fn, 'r') as fd:
t = fd.read() t = fd.read()
check_block(fn, t, 'include', errs) check_block(fn, t, 'include', errs)
check_block(fn, t, 'using', errs) check_block(fn, t, 'using', errs)
check_block(fn, t, 'fwd decl', errs) if suffix == 'h':
check_block(fn, t, 'fwd decl', errs)
check_fwd_decl_sorted(fn, t, errs)
# tests on file pairs: # tests on file pairs:
for fn in allfiles: for fn in allfiles:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment