Skip to content

Commit eae1482

Browse files
committed
feat(utils): add diffing to unasync util
1 parent dab4cca commit eae1482

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

utils/run-unasync.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import difflib
23
import filecmp
34
import os
45
import re
@@ -64,7 +65,25 @@ def run_unasync(output_dir: Path, check: bool = False) -> None:
6465
"",
6566
"Differences:",
6667
]
67-
raise SystemExit("\n".join([*header, *diffs]))
68+
details: list[str] = []
69+
first_diff = next((d for d in diffs if d.startswith("Differs: ")), None)
70+
if first_diff:
71+
mismatch = first_diff.replace("Differs: ", "")
72+
generated = target_dir / Path(mismatch).relative_to(SYNC_DIR)
73+
if generated.exists() and Path(mismatch).exists():
74+
expected_lines = Path(mismatch).read_text().splitlines()
75+
generated_lines = generated.read_text().splitlines()
76+
diff_lines = list(
77+
difflib.unified_diff(
78+
expected_lines,
79+
generated_lines,
80+
fromfile=mismatch,
81+
tofile=str(generated),
82+
lineterm="",
83+
)
84+
)
85+
details.extend(["", "Sample diff:", *diff_lines[:200]])
86+
raise SystemExit("\n".join([*header, *diffs, *details]))
6887

6988

7089
def main() -> None:

0 commit comments

Comments
 (0)