diff --git a/scripts/pr_check.py b/scripts/pr_check.py index e70cab9b2..9cebcafd6 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -44,7 +44,13 @@ def number(s): def runtime(path): - return path.startswith("crates/xcl/src/") and "/tests" not in path and not path.endswith("tests.rs") + """Whether `path` is runtime code (built into xcl.exe), not one of its test files: a `tests.rs` + or `*_tests.rs` module, or a file under a `tests/` directory. Only whole names count, so a + runtime module such as `contests.rs` or `hle/testsupport/mod.rs` still needs a regression run.""" + if not path.startswith("crates/xcl/src/"): + return False + *dirs, name = path[len("crates/xcl/src/"):].split("/") + return not ("tests" in dirs or name == "tests.rs" or name.endswith("_tests.rs")) def check(body, head, files, is_main_ancestor, *, test_only=False): diff --git a/scripts/test_pr_check.py b/scripts/test_pr_check.py index f93667f53..2d6de1395 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -1,6 +1,6 @@ import unittest -from pr_check import check +from pr_check import check, runtime HEAD = "1234567890abcdef" @@ -11,6 +11,29 @@ def changed(path, binary=False): return (path, "modified", binary, lambda: 10) +class RuntimePathTests(unittest.TestCase): + def test_test_files_are_not_runtime(self): + for path in ("crates/xcl/src/gpu/recomp/tests.rs", "crates/xcl/src/gpu/adapter_tests.rs", + "crates/xcl/src/gpu/agility_tests.rs", "crates/xcl/src/hle/tests/vram.rs"): + with self.subTest(path=path): + self.assertFalse(runtime(path)) + + def test_names_that_only_contain_tests_are_runtime(self): + for path in ("crates/xcl/src/gpu/rdna2.rs", "crates/xcl/src/net/requests.rs", "crates/xcl/src/hle/contests.rs", + "crates/xcl/src/hle/testsupport/mod.rs", "crates/xcl/src/gpu/tests_layout.rs"): + with self.subTest(path=path): + self.assertTrue(runtime(path)) + + def test_outside_the_runtime_crate(self): + for path in ("README.md", "scripts/pr_check.py", "tests/testtitle/src/main.rs", "crates/xcl/tests/e2e.rs"): + with self.subTest(path=path): + self.assertFalse(runtime(path)) + + def test_a_runtime_file_named_like_a_test_still_needs_a_regression_run(self): + problems = check(BODY, HEAD, [changed("crates/xcl/src/hle/contests.rs")], lambda _: False) + self.assertTrue(problems and all("Regression run" in problem for problem in problems), problems) + + class TestOnlyApprovalTests(unittest.TestCase): def test_runtime_path_requires_smoke_until_approved(self): files = [changed("crates/xcl/src/hle/d3d12x/vram.rs")]