From ae0bbb9d3cd0592f568a1d09c01471540db1dafe Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 6 Oct 2026 05:09:11 +0200 Subject: [PATCH] fix: fail a truth diff that compared nothing --- scripts/diff_truth.py | 15 ++++++++------- tests/test_truth_diff.py | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/scripts/diff_truth.py b/scripts/diff_truth.py index f22b913a..266f636c 100644 --- a/scripts/diff_truth.py +++ b/scripts/diff_truth.py @@ -179,26 +179,23 @@ def main() -> None: reports: list[dict] = [] formatter = _format_markdown if args.format == "markdown" else _format_terminal + compared = 0 for platform in platforms: truth = _load_truth(args.truth_dir, platform) if truth is None: - if not args.json_output: - print( - f"skip {platform}: no truth YAML in {args.truth_dir}/", - file=sys.stderr, - ) + print(f"skip {platform}: no truth YAML in {args.truth_dir}/", file=sys.stderr) continue try: scraped = load_platform_config(platform, args.platforms_dir) except FileNotFoundError: - if not args.json_output: - print(f"skip {platform}: no scraped config", file=sys.stderr) + print(f"skip {platform}: no scraped config", file=sys.stderr) continue report = diff_platform_truth(truth, scraped) report["platform"] = platform + compared += 1 if args.json_output: reports.append(report) @@ -210,6 +207,10 @@ def main() -> None: json.dump(reports, sys.stdout, indent=2) print() + if compared < len(platforms) and (args.platform or not compared): + print(f"compared {compared} of {len(platforms)} platform(s)", file=sys.stderr) + sys.exit(1) + if __name__ == "__main__": main() diff --git a/tests/test_truth_diff.py b/tests/test_truth_diff.py index 153fd4bc..f4730e24 100644 --- a/tests/test_truth_diff.py +++ b/tests/test_truth_diff.py @@ -56,6 +56,25 @@ class ATargetedModelIsItsOwnArtifact(unittest.TestCase): ) +class ADiffThatComparedNothingFails(unittest.TestCase): + """diff_truth --all skipped every platform without a model and exited 0.""" + + def test_an_empty_truth_directory_is_an_error(self): + import subprocess + import tempfile + + repo = pathlib.Path(__file__).resolve().parent.parent + with tempfile.TemporaryDirectory(dir=str(repo / "tmp")) as directory: + for selection in (["--all"], ["--platform", "retroarch"]): + proc = subprocess.run( + [sys.executable, "scripts/diff_truth.py", *selection, + "--truth-dir", directory, "--json"], + capture_output=True, text=True, cwd=str(repo), timeout=120, + ) + self.assertEqual(proc.returncode, 1, selection) + self.assertIn("skip", proc.stderr) + + class RenameMatching(unittest.TestCase): def test_a_shared_sha1_pairs_the_two_names(self): truth = [_entry("bios_CD_U.bin", sha1="a" * 40)]