diff --git a/tests/it.py b/tests/it.py index 8b6fa89..a9b848b 100755 --- a/tests/it.py +++ b/tests/it.py @@ -17,8 +17,19 @@ # SPDX-License-Identifier: Apache-2.0 from pathlib import Path +import difflib import subprocess +def diff_files(file1, file2): + with file1.open("r") as f1, file2.open("r") as f2: + diff = difflib.unified_diff(f1.readlines(), f2.readlines(), str(file1), str(file2)) + diff = list(diff) + if diff: + for line in diff: + print(line, end="") + exit(1) + + basedir = Path(__file__).parent.absolute() rootdir = basedir.parent @@ -26,7 +37,7 @@ hawkeye = rootdir / "target" / "debug" / "hawkeye" subprocess.run([hawkeye, "format", "--fail-if-unknown", "--fail-if-updated=false", "--dry-run"], cwd=(basedir / "load_header_path"), check=True) -subprocess.run(["diff", "main.rs.expected", "main.rs.formatted"], cwd=(basedir / "load_header_path"), check=True) +diff_files(basedir / "load_header_path" / "main.rs.expected", basedir / "load_header_path" / "main.rs.formatted") subprocess.run([hawkeye, "format", "--fail-if-unknown", "--fail-if-updated=false", "--dry-run"], cwd=(basedir / "regression_blank_line"), check=True) -subprocess.run(["diff", "main.rs.expected", "main.rs.formatted"], cwd=(basedir / "regression_blank_line"), check=True) +diff_files(basedir / "regression_blank_line" / "main.rs.expected", basedir / "regression_blank_line" / "main.rs.formatted")