Skip to content

Commit 3dbce37

Browse files
committed
generate-jobs: print diff in case of failure
This makes a CI failure more useful. In one case, the CI reported "differs from existing" without saying how and locally the check passed.
1 parent e53d723 commit 3dbce37

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

hack/generate-jobs.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import argparse
1818
import configparser
19-
import filecmp
19+
import difflib
2020
import os
2121
import pathlib
2222
import shutil
@@ -107,22 +107,24 @@ def generate_one(path: pathlib.Path, verify: bool) -> typing.List[str]:
107107
errors.append(f"Can't verify content: {out} doesn't exist")
108108
continue
109109
else:
110-
equal = filecmp.cmp(out, tmp.name, shallow=False)
110+
with open(tmp.name) as expected, open(out) as actual:
111+
diff = difflib.context_diff(actual.readlines(), expected.readlines(),
112+
fromfile="actual", tofile="expected")
113+
diff = ''.join(diff)
111114
if verify:
112115
os.unlink(tmp.name)
113-
if not equal:
116+
if diff != "":
114117
errors.append(
115-
f"Generated content for {out} differs from existing"
118+
f"Generated content for {out} differs from existing:\n{diff}"
116119
)
117120
continue
118-
if equal:
121+
if diff == "":
119122
os.unlink(tmp.name)
120123
continue
121124
shutil.move(tmp.name, out)
122125

123126
return errors
124127

125-
126128
def main(argv):
127129
"""Entry point."""
128130
parser = argparse.ArgumentParser(

0 commit comments

Comments
 (0)