diff --git a/bin/task_bench/framework_tests.py b/bin/task_bench/framework_tests.py index 6901f99d..d86a3811 100644 --- a/bin/task_bench/framework_tests.py +++ b/bin/task_bench/framework_tests.py @@ -3,13 +3,15 @@ import posixpath import re -from mutate_changes.changed_lines import is_test, STRYKER +from mutate_changes.changed_lines import is_test -# PHPUnit's default suffix, wherever the file stands; node --test's `*-test`, `*_test`, `test-*` and `test` stems, in each suffix -# Stryker covers. node --test's `*.test.*` is `is_test`'s already. -FRAMEWORK_NAME = re.compile(rf".*Test\.php|(?:.*[-_]test|test|test-.*)(?:{'|'.join(re.escape(suffix) for suffix in STRYKER)})") +# The suffixes `node --test` runs: JavaScript, and TypeScript where Node strips the types; not `.jsx` or `.tsx`, which it doesn't find. +NODE_SUFFIXES = (".cjs", ".cts", ".js", ".mjs", ".mts", ".ts") +# PHPUnit's default suffix, wherever the file stands; node --test's `*-test`, `*_test`, `test-*` and `test` stems, in each of its +# suffixes. node --test's `*.test.*` is `is_test`'s already. +FRAMEWORK_NAME = re.compile(rf".*Test\.php|(?:.*[-_]test|test|test-.*)(?:{'|'.join(re.escape(suffix) for suffix in NODE_SUFFIXES)})") def is_test_file(path: str) -> bool: - """Whether path is a test by its name or folder alone, as `is_test` or PHPUnit or `node --test` tells it.""" + """Whether path is a test by its name or folder alone, as `is_test`, PHPUnit or `node --test` tells it.""" return is_test(path) or bool(FRAMEWORK_NAME.fullmatch(posixpath.basename(path))) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 9ee6c038..50bc2cfa 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -37,9 +37,10 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. - Check. The test command runs over the planted tree with each file that is no test as Haiku left it; a fix passes where it exits 0. A test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder. The bench tells a test by its path: a folder named `test`, `tests` or `__tests__`, or a file named `test_*.py`, `*_test.py`, - `*_test.go`, `*.test.*`, `*.spec.*` or `*Test.php`, or, in a JavaScript or TypeScript suffix, `*-test.*`, `*_test.*`, - `test-*.*` or `test.*`. A test of any other name counts as code, so Haiku's change to it stands. In a Rust file, each inline - `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it + `conftest.py`, `*_test.go`, `*.test.*`, `*.spec.*` or `*Test.php`. It tells one more by the names `node --test` finds, in a + `.js`, `.cjs`, `.mjs`, `.ts`, `.cts` or `.mts` file: `*-test.*`, `*_test.*`, `test-*.*` and `test.*`. A test of any other + name counts as code, so Haiku's change to it stands. In a Rust file, each inline `#[cfg(test)]` module stands as the planted + file has it, and the rest is as Haiku left it. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where Haiku's file lacks a module of the planted file's or a declaration as written there, or the planted file has inline modules and Haiku's cannot be told apart, the planted file stands whole; where the planted file's inline modules cannot be told apart, or it has none and diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index 5f9fd086..973d5178 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -205,7 +205,7 @@ def keep_rust_tests(planted_file: str, target: str) -> None: def of_tests(path: str, rust_tests: typing.AbstractSet[str] = frozenset()) -> bool: - """Whether path is a test by its path alone, as `is_test_file` tells it, or one of rust_tests.""" + """Whether path is a test by its path alone, or one of rust_tests.""" return is_test_file(path) or "testdata" in pathlib.PurePath(path).parts or path in rust_tests diff --git a/bin/task_bench/test_framework_tests.py b/bin/task_bench/test_framework_tests.py index f8521e72..c41eb4f5 100644 --- a/bin/task_bench/test_framework_tests.py +++ b/bin/task_bench/test_framework_tests.py @@ -10,7 +10,7 @@ class IsTestFileTest(unittest.TestCase): self.assertTrue(is_test_file(path)) def test_tells_the_names_node_test_finds_in_each_suffix_stryker_covers(self): - for path in ("src/pick-test.js", "pick_test.mjs", "src/test-pick.cjs", "src/test.ts", "a/b/pick-test.tsx", "test.jsx", "x_test.mts", "test-x.cts"): + for path in ("src/pick-test.js", "pick_test.mjs", "src/test-pick.cjs", "src/test.ts", "a/b/pick-test.ts", "test.js", "x_test.mts", "test-x.cts"): with self.subTest(path=path): self.assertTrue(is_test_file(path)) @@ -20,6 +20,6 @@ class IsTestFileTest(unittest.TestCase): self.assertTrue(is_test_file(path)) def test_takes_other_code_as_code(self): - for path in ("src/Pick.php", "src/Tester.php", "src/PickTest.phps", "src/pick.js", "src/latest.js", "src/pick-tests.js", "src/pickTest.js", "src/test-pick.json", "src/contest.ts", "src/Test.php.bak"): + for path in ("src/Pick.php", "src/Tester.php", "src/PickTest.phps", "src/pick.js", "src/latest.js", "src/pick-tests.js", "src/pickTest.js", "src/test-pick.json", "src/pick-test.jsx", "src/pick-test.tsx", "src/contest.ts", "src/Test.php.bak"): with self.subTest(path=path): self.assertFalse(is_test_file(path))