From 47084dc3dfa0e320127fde1515d504d3488a9ddb Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 26 Nov 2026 11:03:39 +0100 Subject: [PATCH] Test the planters' edges that mutants survived --- bin/task_bench/php_bugs.py | 8 +++++--- bin/task_bench/test_php_bugs.py | 6 ++++++ bin/task_bench/test_typescript_bugs.py | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bin/task_bench/php_bugs.py b/bin/task_bench/php_bugs.py index 7bd57360..9543efe9 100644 --- a/bin/task_bench/php_bugs.py +++ b/bin/task_bench/php_bugs.py @@ -48,9 +48,11 @@ def planted(mutator: dict, diff: str, files: list[str]) -> Mutant | None: the longest of `files` that ends that path.""" logged = mutator["originalFilePath"] path = max((path for path in files if logged == path or logged.endswith(f"/{path}")), key=len, default=None) + if path is None: + return None start = mutator["originalStartLine"] - found = changed(diff, mutator["originalSourceCode"].split("\n"), start) if path else None - return Mutant(path, found[0], f"{path}:{start} {mutator['mutatorName']}", found[1], found[2]) if path and found else None + found = changed(diff, mutator["originalSourceCode"].split("\n"), start) + return Mutant(path, found[0], f"{path}:{start} {mutator['mutatorName']}", found[1], found[2]) if found else None def changed(diff: str, lines: list[str], start: int) -> tuple[int, tuple[bytes, ...], tuple[bytes, ...]] | None: @@ -59,7 +61,7 @@ def changed(diff: str, lines: list[str], start: int) -> tuple[int, tuple[bytes, The diff's one hunk gives no line numbers. So the hunk's lines are found among `lines`, the file's, around `start`, the line Infection logs as the one the mutated code starts on. None where the diff holds no change, or where its lines stand around - `start` nowhere or more than once.""" + `start` nowhere or more than once, as do those of a diff with a second hunk.""" hunk = diff.partition("@@ @@\n")[2].split("\n") # An empty line of the file is an empty line of the hunk; any other line opens with a space, a minus or a plus. body = [(line[:1] if line[:1] in ("-", "+") else " ", line[1:]) for line in hunk] diff --git a/bin/task_bench/test_php_bugs.py b/bin/task_bench/test_php_bugs.py index 75513d82..deebb7da 100644 --- a/bin/task_bench/test_php_bugs.py +++ b/bin/task_bench/test_php_bugs.py @@ -145,6 +145,9 @@ class ChangedTest(unittest.TestCase): self.assertIsNone(changed("@@ @@\n \t{\n \t\t$sum = 0;", LINES, 10)) self.assertIsNone(changed("", LINES, 10)) + def test_is_none_where_the_diff_holds_a_second_hunk(self): + self.assertIsNone(changed(OPERATOR_DIFF + "\n@@ @@\n \t\t\t}\n-\t\t}\n+\t\t};\n \t\treturn $sum;", LINES, 15)) + def test_what_it_returns_plants_as_the_mutant(self): for diff, start in ((OPERATOR_DIFF, 12), (FOREACH_DIFF, 11), (TERNARY_DIFF, 21), (VISIBILITY_DIFF, 19)): with self.subTest(start=start): @@ -242,6 +245,9 @@ class TaskTextTest(unittest.TestCase): self.assertEqual(task_text(failing("Probe\\Tests\\PickTest::testNamesOne", *lines)), "got 3, want 5") self.assertEqual(task_text(failing("Probe\\Tests\\PickTest::testNamesOne with data set #0 (1, 'one')", *lines)), "got 3, want 5") + def test_reads_a_listed_test_that_names_no_class(self): + self.assertEqual(task_text(failing("testNamesOne", "got 3, want 5")), "got 3, want 5") + def test_is_none_where_the_message_does_not_say_anything_beyond_the_test(self): self.assertIsNone(task_text(failing("Probe\\Tests\\PickTest::testNamesOne", "testNamesOne failed", "", "/w/tests/PickTest.php:17"))) diff --git a/bin/task_bench/test_typescript_bugs.py b/bin/task_bench/test_typescript_bugs.py index 9939a0fe..4e5d7fb5 100644 --- a/bin/task_bench/test_typescript_bugs.py +++ b/bin/task_bench/test_typescript_bugs.py @@ -3,6 +3,8 @@ output tells Haiku. PICK's mutants and FAILING are what Stryker 10.1.1 and Node.js 24.19.0 wrote for a small project, the mutants with the keys the planter reads. The other mutants and outputs are made up in the same form.""" +import contextlib +import io import json import pathlib import sys @@ -130,6 +132,13 @@ class ChangedTest(unittest.TestCase): def test_a_replacement_of_more_lines_is_as_many_lines(self): self.assertEqual(changed(OPERATOR["location"], "item >\n\t\t\tfloor", LINES), (4, (LINES[3],), (b"\t\tif (item >", b"\t\t\tfloor) {"))) + def test_reaches_the_files_first_column_and_its_last_line(self): + self.assertEqual(changed(reported("M", "", (1, 1), (1, 8))["location"], "", LINES[:2]), (1, (LINES[0],), (LINES[0][7:],))) + self.assertEqual(changed(reported("M", "0", (2, 12), (2, 13))["location"], "0", LINES[:2]), (2, (LINES[1],), (LINES[1],))) + + def test_a_mutant_that_replaces_no_code_adds_its_own(self): + self.assertEqual(changed(reported("M", "!", (4, 7), (4, 7))["location"], "!", LINES), (4, (LINES[3],), (b"\t\tif (!item >= floor) {",))) + def test_counts_a_column_in_utf_16_code_units(self): now = 'export const tag = (n: number): string => "é😀" + (true ? "s" : "");'.encode() self.assertEqual(changed(AFTER_WIDE_TEXT["location"], "true", LINES), (11, (LINES[10],), (now,))) @@ -199,6 +208,15 @@ class KilledMutantsTest(unittest.TestCase): self.assertEqual(found, Failure("Stryker exited 1:\nthe tool's last words")) self.assertFalse((self.top / "reports").exists()) + def test_says_on_stderr_only_that_it_could_not_remove_a_report(self): + def blocked(argv: list[str], cwd: str) -> Ran: + (self.top / "reports/mutation/mutation.json/held").mkdir(parents=True) + return Ran(0, "") + for run, said in ((self.stryker(None), ""), (blocked, f"could not remove {self.top}/reports/mutation/mutation.json: ")): + with self.subTest(said=said), contextlib.redirect_stderr(io.StringIO()) as stderr: + self.assertIsInstance(killed_mutants(str(self.top), ["src/pick.ts"], run, 1), Failure) + self.assertEqual(stderr.getvalue()[:len(said) or None], said) + def test_passes_on_a_run_that_could_not_start(self): failure = Failure("npx could not start: No such file or directory") self.assertIs(killed_mutants(str(self.top), ["src/pick.ts"], lambda argv, cwd: failure, 1), failure)