1414import difflib
1515import lzma
1616
17+ # debug = True will use the command-line diff (or xzdiff) to check the results of difflib.
18+ debug = False
19+
1720_RE_COMBINE_WHITESPACE = re .compile (r"\s+" )
1821
19- # FIXME: Replace "diff" with difflib.
2022def normalize_file_lines (file_path ):
2123 """Yield normalized lines from a file, supporting both regular and XZ-compressed files."""
2224 open_func = lzma .open if file_path .endswith ('.xz' ) else open
@@ -136,11 +138,9 @@ def run_test(test, program):
136138 fh , outfile = tempfile .mkstemp (suffix = "_" + testbasename .replace (".test" , ".out" ))
137139 os .close (fh )
138140 expfile = test .replace (".test" , ".exp" )
139- diff = "diff"
140141 if not os .access (expfile , os .R_OK ) and os .access (expfile + ".xz" , os .R_OK ):
141142 expfile = expfile + ".xz"
142143 outfile = outfile + ".xz"
143- diff = "xzdiff"
144144
145145 print ("{:<60}" .format ("Running " + test + " :" ), end = " " )
146146 start_time = time .time ()
@@ -159,9 +159,11 @@ def run_test(test, program):
159159 return True
160160 else :
161161 print_rich (f"[bold red]FAILED![/] { elapsed_time :6.2f} " )
162- print (truncate_lines (diff_output , max_lines = 20 )) # f"{diff} -uiEBw -- {expfile} {outfile}")
163- #print(subprocess.getoutput(f"{diff} -uiEBw -- {expfile} {outfile}"))
164- assert runcmd (f"{ diff } -iEBwq -- { expfile } { outfile } " ) != 0 , f"{ generate_unified_diff (expfile , outfile )} "
162+ print (truncate_lines (diff_output , max_lines = 20 ))
163+ if debug :
164+ diff = "xzdiff" if expfile .endswith (".xz" ) else "diff"
165+ print (subprocess .getoutput (f"{ diff } -uiEBw -- { expfile } { outfile } " ))
166+ assert runcmd (f"{ diff } -iEBwq -- { expfile } { outfile } " ) != 0 , diff_output
165167 return False
166168
167169
0 commit comments