omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / native / v2 / test_verdict.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Exercise the real runner's terminal verdict, without an Omega compiler. |
| 3 | |
| 4 | Only the final shell decision is executed. These are host control-flow tests, |
| 5 | not native caller execution or ABI-v2 qualification. |
| 6 | """ |
| 7 | |
| 8 | import pathlib |
| 9 | import subprocess |
| 10 | import unittest |
| 11 | |
| 12 | |
| 13 | class VerdictTests(unittest.TestCase): |
| 14 | @classmethod |
| 15 | def setUpClass(cls): |
| 16 | runner = pathlib.Path(__file__).with_name("run.sh").read_text() |
| 17 | marker = "for l in $notrun;" |
| 18 | if runner.count(marker) != 1: |
| 19 | raise AssertionError("cannot identify the runner's terminal verdict uniquely") |
| 20 | cls.verdict = marker + runner.split(marker, 1)[1] |
| 21 | |
| 22 | def run_verdict(self, fails, notrun): |
| 23 | return subprocess.run( |
| 24 | ["sh", "-eu", "-c", 'fails=$1; notrun=$2\n' + self.verdict, |
| 25 | "native-v2-verdict", str(fails), notrun], |
| 26 | text=True, capture_output=True, check=False, |
| 27 | ) |
| 28 | |
| 29 | def test_complete_success(self): |
| 30 | result = self.run_verdict(0, "") |
| 31 | self.assertEqual(result.returncode, 0, result.stdout + result.stderr) |
| 32 | self.assertEqual(result.stdout, "NATIVE-V2 PASS (not run: none)\n") |
| 33 | self.assertEqual(result.stderr, "") |
| 34 | |
| 35 | def test_each_missing_toolchain_is_not_run(self): |
| 36 | for language in ("c++", "python", "rust", "zig", "go"): |
| 37 | with self.subTest(language=language): |
| 38 | result = self.run_verdict(0, " " + language) |
| 39 | self.assertEqual(result.returncode, 1, result.stdout + result.stderr) |
| 40 | self.assertIn("NOT_RUN " + language + " caller: toolchain not installed\n", |
| 41 | result.stdout) |
| 42 | self.assertIn("NATIVE-V2 NOT_RUN (not run: " + language + ")\n", |
| 43 | result.stdout) |
| 44 | self.assertNotIn("NATIVE-V2 PASS", result.stdout) |
| 45 | self.assertEqual(result.stderr, "") |
| 46 | |
| 47 | def test_multiple_missing_toolchains_are_not_run(self): |
| 48 | result = self.run_verdict(0, " zig go") |
| 49 | self.assertEqual(result.returncode, 1, result.stdout + result.stderr) |
| 50 | self.assertIn("NOT_RUN zig caller: toolchain not installed\n", result.stdout) |
| 51 | self.assertIn("NOT_RUN go caller: toolchain not installed\n", result.stdout) |
| 52 | self.assertIn("NATIVE-V2 NOT_RUN (not run: zig go)\n", result.stdout) |
| 53 | self.assertNotIn("NATIVE-V2 PASS", result.stdout) |
| 54 | |
| 55 | def test_failure_remains_failure(self): |
| 56 | result = self.run_verdict(1, "") |
| 57 | self.assertEqual(result.returncode, 1, result.stdout + result.stderr) |
| 58 | self.assertEqual(result.stdout, "NATIVE-V2 FAIL 1\n") |
| 59 | |
| 60 | def test_failure_takes_precedence_over_not_run(self): |
| 61 | result = self.run_verdict(1, " zig") |
| 62 | self.assertEqual(result.returncode, 1, result.stdout + result.stderr) |
| 63 | self.assertIn("NOT_RUN zig caller: toolchain not installed\n", result.stdout) |
| 64 | self.assertIn("NATIVE-V2 FAIL 1\n", result.stdout) |
| 65 | self.assertNotIn("NATIVE-V2 PASS", result.stdout) |
| 66 | self.assertNotIn("NATIVE-V2 NOT_RUN", result.stdout) |
| 67 | |
| 68 | |
| 69 | if __name__ == "__main__": |
| 70 | unittest.main(verbosity=2) |