Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/test_cf_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_mem_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shader_diff_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ def test_the_defaults_are_unchanged(self):


if __name__ == "__main__":
unittest.main()
unittest.main()
3 changes: 2 additions & 1 deletion tools/fmisc_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tools/mem_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down