diff --git a/tests/test_cf_diff.py b/tests/test_cf_diff.py index 03f1913470..19f87d837f 100644 --- a/tests/test_cf_diff.py +++ b/tests/test_cf_diff.py @@ -53,6 +53,16 @@ def test_a_run_where_every_program_was_skipped_is_not_a_success(capsys, monkeypa assert "no program ran: every one was skipped" in capsys.readouterr().out +@pytest.mark.parametrize("status, code", [ + ("mismatch", 1), # every program mismatched: a mismatch is not "nothing ran" + ("match", 0), # every program matched +]) +def test_a_suite_run_exits_by_what_was_compared(status, code, capsys, monkeypatch): + monkeypatch.setattr(cf_diff, "run_case", lambda *args, **kwargs: (status, "detail")) + assert cf_diff.main(["--programs", "2", "--seed", "1"]) == code + assert "no program ran" not in capsys.readouterr().out + + @pytest.mark.parametrize("statuses, code", [ (["skip", "skip"], 2), # nothing was compared (["skip", "mismatch"], 1), # a mismatch outranks "nothing else ran" diff --git a/tests/test_mem_diff.py b/tests/test_mem_diff.py index 62268f65d1..0ea8ec4d2d 100644 --- a/tests/test_mem_diff.py +++ b/tests/test_mem_diff.py @@ -61,6 +61,18 @@ def test_a_run_where_every_program_was_skipped_is_not_a_success(self): self.assertEqual(rc, 2, out.getvalue()) self.assertIn("no program ran: every one was skipped", out.getvalue()) + def test_a_run_exits_by_what_was_compared(self): + import contextlib + import io + from unittest import mock + for status, code in (("mismatch", 1), ("match", 0)): + out = io.StringIO() + with self.subTest(status=status), \ + mock.patch.object(md, "run_one", lambda *args, status=status: (status, "detail")), \ + contextlib.redirect_stdout(out): + self.assertEqual(md.main(["--programs", "2", "--seed", "1"]), code, out.getvalue()) + self.assertNotIn("no program ran", out.getvalue()) + class Reference(unittest.TestCase): """The reference model on hand-made cases (the expected words are worked out by hand).""" diff --git a/tests/test_shader_diff_exit.py b/tests/test_shader_diff_exit.py index 1b7416d4c1..d2e65480fb 100644 --- a/tests/test_shader_diff_exit.py +++ b/tests/test_shader_diff_exit.py @@ -127,4 +127,4 @@ def test_the_defaults_are_unchanged(self): if __name__ == "__main__": - unittest.main() + unittest.main() \ No newline at end of file diff --git a/tools/fmisc_diff.py b/tools/fmisc_diff.py index 4194d30b5d..48b76f5c15 100644 --- a/tools/fmisc_diff.py +++ b/tools/fmisc_diff.py @@ -59,7 +59,8 @@ python -I tools/fmisc_diff.py --self-test Exit 0 when every program matches, 1 on a mismatch (the shortest failing program is printed after removing -instructions that do not matter), 2 on a harness error or when every program was skipped (nothing was compared), 77 when the requested hardware oracle is unavailable. +instructions that do not matter), 2 on a harness error or when every program was skipped (nothing was +compared), 77 when the requested hardware oracle is unavailable. Skips are counted with their reasons. """ import argparse diff --git a/tools/mem_diff.py b/tools/mem_diff.py index 6e1efc1567..9523d04f25 100644 --- a/tools/mem_diff.py +++ b/tools/mem_diff.py @@ -31,7 +31,8 @@ python -I tools/mem_diff.py --self-test Exit code 0 when every program matches, 1 on a mismatch (the first one is printed with its listing), 2 on a -harness error or when every program was skipped (nothing was compared). Skips are counted with their reasons, never silent. +harness error or when every program was skipped (nothing was compared). Skips are counted with their reasons, +never silent. """ import argparse import gc