Skip to content

Commit 2b8b9b2

Browse files
committed
feat(utils): add diffing to unasync util
1 parent 33eed01 commit 2b8b9b2

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
@@ -65,7 +66,25 @@ def run_unasync(output_dir: Path, check: bool = False) -> None:
6566
"",
6667
"Differences:",
6768
]
68-
raise SystemExit("\n".join([*header, *diffs]))
69+
details: list[str] = []
70+
first_diff = next((d for d in diffs if d.startswith("Differs: ")), None)
71+
if first_diff:
72+
mismatch = first_diff.replace("Differs: ", "")
73+
generated = target_dir / Path(mismatch).relative_to(SYNC_DIR)
74+
if generated.exists() and Path(mismatch).exists():
75+
expected_lines = Path(mismatch).read_text().splitlines()
76+
generated_lines = generated.read_text().splitlines()
77+
diff_lines = list(
78+
difflib.unified_diff(
79+
expected_lines,
80+
generated_lines,
81+
fromfile=mismatch,
82+
tofile=str(generated),
83+
lineterm="",
84+
)
85+
)
86+
details.extend(["", "Sample diff:", *diff_lines[:200]])
87+
raise SystemExit("\n".join([*header, *diffs, *details]))
6988

7089

7190
def main() -> None:

0 commit comments

Comments
 (0)