Skip to content

Commit 511486d

Browse files
committed
Rework file diff (show line differences)
1 parent ce53586 commit 511486d

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

misc/scripts/library-coverage/compare-files.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import os
33
import settings
4-
import filecmp
4+
import difflib
55

66
"""
77
This script compares the generated CSV coverage files with the ones in the codebase.
@@ -14,10 +14,21 @@ def check_file_exists(file):
1414
sys.exit(1)
1515

1616

17+
def ignore_line_ending(ch):
18+
return difflib.IS_CHARACTER_JUNK(ch, ws=" \r\n")
19+
20+
1721
def compare_files(file1, file2):
18-
filecmp.clear_cache()
19-
if not filecmp.cmp(file1, file2):
20-
print("Error: The generated files do not match the ones in the codebase. Please check and fix file '" +
22+
has_differences = False
23+
diff = difflib.ndiff(open(file1).readlines(),
24+
open(file2).readlines(), None, ignore_line_ending)
25+
for line in diff:
26+
if line.startswith("+") or line.startswith("-"):
27+
print(line, end="", file=sys.stderr)
28+
has_differences = True
29+
30+
if has_differences:
31+
print("Error: The generated file doesn't match the one in the codebase. Please check and fix file '" +
2132
file1 + "'.", file=sys.stderr)
2233
sys.exit(1)
2334

0 commit comments

Comments
 (0)