Skip to content

Commit acb886f

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 acb886f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

hack/generate-jobs.py

Lines changed: 7 additions & 4 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,12 +107,16 @@ 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)
114+
equal = diff == ""
111115
if verify:
112116
os.unlink(tmp.name)
113117
if not equal:
114118
errors.append(
115-
f"Generated content for {out} differs from existing"
119+
f"Generated content for {out} differs from existing:\n{diff}"
116120
)
117121
continue
118122
if equal:
@@ -122,7 +126,6 @@ def generate_one(path: pathlib.Path, verify: bool) -> typing.List[str]:
122126

123127
return errors
124128

125-
126129
def main(argv):
127130
"""Entry point."""
128131
parser = argparse.ArgumentParser(

0 commit comments

Comments
 (0)