Skip to content

Commit 3934bcd

Browse files
committed
Merge branch 'albert-github-feature/issue_11722'
2 parents d6fd0db + 4828159 commit 3934bcd

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

testing/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# run all tests sequentially (keep for backward compatibility)
22
add_custom_target(tests
33
COMMENT "Running doxygen tests..."
4-
COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/testing/runtests.py --xmlxsd --doxygen ${PROJECT_BINARY_DIR}/bin/doxygen --inputdir ${PROJECT_SOURCE_DIR}/testing --outputdir ${PROJECT_BINARY_DIR}/testing
4+
COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/testing/runtests.py --doxygen ${PROJECT_BINARY_DIR}/bin/doxygen --inputdir ${PROJECT_SOURCE_DIR}/testing --outputdir ${PROJECT_BINARY_DIR}/testing
55
DEPENDS doxygen ${update_doxmlparser_dependency}
66
)
77

@@ -15,6 +15,6 @@ foreach(TEST_FILE ${TEST_FILES})
1515
string(REGEX REPLACE "^.*/([0-9][0-9][0-9]*).*$" "\\1" TEST_ID "${TEST_FILE}")
1616
# add a test target for each test
1717
add_test(NAME ${TEST_NAME}
18-
COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/testing/runtests.py --id ${TEST_ID} --xmlxsd --doxygen $<TARGET_FILE:doxygen> --inputdir ${PROJECT_SOURCE_DIR}/testing --outputdir ${PROJECT_BINARY_DIR}/testing
18+
COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/testing/runtests.py --id ${TEST_ID} --doxygen $<TARGET_FILE:doxygen> --inputdir ${PROJECT_SOURCE_DIR}/testing --outputdir ${PROJECT_BINARY_DIR}/testing
1919
)
2020
endforeach()

testing/runtests.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,39 @@ def __init__(self,args,test):
7979
self.test_out = self.args.outputdir+'/test_output_'+self.test_id
8080
self.prepare_test()
8181

82-
def compare_ok(self,got_file,expected_file,name):
82+
# Compares 'got_file' against 'expected_file'.
83+
# Returns (True,Msg) if there is a difference or one of the files does not exist and (False,'') otherwise
84+
def compare_ok(self, got_file, expected_file):
8385
if not os.path.isfile(got_file):
84-
return (True,'%s absent' % got_file)
85-
elif not os.path.isfile(expected_file):
86-
return (True,'%s absent' % expected_file)
87-
else:
88-
diff = xpopen('diff -b -w -u %s %s' % (got_file,expected_file))
86+
return (True, f'{got_file} absent')
87+
if not os.path.isfile(expected_file):
88+
return (True, f'{expected_file} absent')
89+
90+
def _write_filtered_tmp(src_path, tmp_path):
91+
# Read, split on tags to add newlines, drop empty lines, and write to tmp
92+
with xopen(src_path, 'r') as f, xopen(tmp_path, 'w') as out_file:
93+
filtered = [line for line in f.read().
94+
replace("<", "\n<").replace(">", ">\n").splitlines() if line.strip()]
95+
out_file.write('\n'.join(filtered)+'\n')
96+
97+
got_file_tmp = got_file + "_got"
98+
expected_file_tmp = got_file + "_ref"
99+
100+
try:
101+
for src, tmp in ((got_file, got_file_tmp), (expected_file, expected_file_tmp)):
102+
_write_filtered_tmp(src, tmp)
103+
104+
diff = xpopen(f'diff -b -w -u {got_file_tmp} {expected_file_tmp}')
89105
if diff and not diff.startswith("No differences"):
90-
return (True,'Difference between generated output and reference:\n%s' % diff)
91-
return (False,'')
106+
return (True, f'Difference between generated output and reference:\n{diff}')
107+
return (False, '')
108+
finally:
109+
# Ensure cleanup even if diff or write fails
110+
for tmp in (got_file_tmp, expected_file_tmp):
111+
try:
112+
os.remove(tmp)
113+
except OSError:
114+
pass
92115

93116
def cleanup_xmllint(self,errmsg):
94117
msg = errmsg.split('\n')
@@ -328,7 +351,7 @@ def perform_test(self,testmgr):
328351
with xopen(out_file,'w') as f:
329352
print(data,file=f)
330353
ref_file='%s/%s/%s' % (self.args.inputdir,self.test_id,check)
331-
(failed_xml,xml_msg) = self.compare_ok(out_file,ref_file,self.test_name)
354+
(failed_xml,xml_msg) = self.compare_ok(out_file,ref_file)
332355
if failed_xml:
333356
msg+= (xml_msg,)
334357
break

0 commit comments

Comments
 (0)