diff --git a/docs/testing.md b/docs/testing.md index 07ff151255..f279548ceb 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -401,7 +401,9 @@ whose Metal device is "Apple Paravirtual device" (Metal family Mac2, not Apple7) subgroups, so the wave64 and "32 lanes on request" tests skip there (about 75 of 190 in November 2026), and Mesa's KosmicKrisp finds no device. `macos-15` can't build the runtime: Xcode 16's libc++ has no floating-point `std::from_chars`. A test known to fail on MoltenVK is listed in the step's `EXPECTED_FAILURES` with the pull -request or coordination-issue finding that tracks it; it still runs, and `scripts/ci_expected_failures.py` fails the step on any other failure. +request or coordination-issue finding that tracks it; it still runs, and `scripts/ci_expected_failures.py` fails the step +on any other failure. It takes `FAILED_LIST EXIT_STATUS [EXPECTED ...]`, answers `--help`, and reports a list it cannot +read or a non-numeric status as one line with exit code 2. ## GPUs without fragment barycentrics (NVIDIA Volta, Pascal and older) diff --git a/scripts/ci_expected_failures.py b/scripts/ci_expected_failures.py index b07b8de3c6..2e8fafb203 100644 --- a/scripts/ci_expected_failures.py +++ b/scripts/ci_expected_failures.py @@ -4,8 +4,9 @@ FAILED_LIST is a file with one failed test name per line, EXIT_STATUS the test runner's exit status, and each EXPECTED argument one or more whitespace-separated test names (so a workflow can pass one quoted list). Exits 1 when a -test outside EXPECTED failed, or when the runner failed without naming a test (a crash, a build error). An expected -failure that passed gets a GitHub Actions notice, so the list in the workflow can shrink. +test outside EXPECTED failed, or when the runner failed without naming a test (a crash, a build error); 2 on a usage +error, including a non-integer EXIT_STATUS or a FAILED_LIST that cannot be read, reported as one line. `--help` prints +this text. An expected failure that passed gets a GitHub Actions notice, so the list in the workflow can shrink. """ import sys @@ -26,13 +27,25 @@ def judge(failed: list[str], status: int, expected: list[str]) -> tuple[int, lis def main(argv: list[str]) -> int: + if argv and argv[0] in ("-h", "--help"): + print(__doc__.strip()) + return 0 if len(argv) < 2: print(__doc__.strip(), file=sys.stderr) return 2 - with open(argv[0], encoding="utf-8") as f: - failed = [line.strip() for line in f if line.strip()] + try: + status = int(argv[1]) + except ValueError: + print(f"ci_expected_failures: EXIT_STATUS {argv[1]!r} is not an integer", file=sys.stderr) + return 2 + try: + with open(argv[0], encoding="utf-8") as f: + failed = [line.strip() for line in f if line.strip()] + except OSError as e: + print(f"ci_expected_failures: {argv[0]}: {e.strerror or e}", file=sys.stderr) + return 2 expected = [name for arg in argv[2:] for name in arg.split()] - code, lines = judge(failed, int(argv[1]), expected) + code, lines = judge(failed, status, expected) print("\n".join(lines)) return code diff --git a/tests/test_ci_expected_failures.py b/tests/test_ci_expected_failures.py index 1df4ec2171..ba280bccb0 100644 --- a/tests/test_ci_expected_failures.py +++ b/tests/test_ci_expected_failures.py @@ -65,6 +65,31 @@ def test_missing_arguments_is_a_usage_error(self): with contextlib.redirect_stderr(io.StringIO()): self.assertEqual(cef.main([]), 2) + def test_help_prints_the_usage_and_succeeds(self): + out = io.StringIO() + with contextlib.redirect_stdout(out): + self.assertEqual(cef.main(["--help"]), 0) + self.assertIn("FAILED_LIST EXIT_STATUS", out.getvalue()) + + def test_a_list_that_cannot_be_read_is_one_error_line(self): + with tempfile.TemporaryDirectory() as tmp: + missing = Path(tmp) / "absent.txt" + err = io.StringIO() + with contextlib.redirect_stderr(err): + self.assertEqual(cef.main([str(missing), "8"]), 2) + self.assertEqual(err.getvalue().count("\n"), 1) + self.assertIn(str(missing), err.getvalue()) + + def test_a_non_integer_status_is_one_error_line(self): + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "failed.txt" + path.write_text("a\n", encoding="utf-8") + err = io.StringIO() + with contextlib.redirect_stderr(err): + self.assertEqual(cef.main([str(path), "x"]), 2) + self.assertEqual(err.getvalue().count("\n"), 1) + self.assertIn("'x'", err.getvalue()) + if __name__ == "__main__": unittest.main()