Answer stability round 1: 1 🔴, 2 🟡 (0 misread); no outcomes file means no mutant, two tests use subTest, and a test's name fits its assertion

This commit is contained in:
2026-11-24 02:57:18 +01:00
parent 70fbc2a02d
commit b38e8a1931
9 changed files with 56 additions and 28 deletions
+16 -10
View File
@@ -1,6 +1,7 @@
"""task-bench's Rust planter: which files cargo-mutants mutates, how its diffs become mutants and what cargo test's output tells Haiku.
The diffs, the outcomes and cargo test's output are what cargo-mutants 27.1.0 and Rust 1.100.0 wrote for a small project."""
PICK's two diffs, ASSERTION and TWO_FAILED are what cargo-mutants 27.1.0 and Rust 1.100.0 wrote for a small project, and OUTCOMES
holds the keys the planter reads of that run's outcomes. The other diffs and outputs are made up in the same form."""
import json
import pathlib
import sys
@@ -29,7 +30,6 @@ pub fn total(items: &[i32]) -> i32 {
sum
}
"""
# A mutant that swaps an operator, and one that replaces a function's body.
OPERATOR_DIFF = b"""--- src/pick.rs
+++ replace += with -= in total
@@ -3,12 +3,12 @@
@@ -135,10 +135,11 @@ class ChangedTest(unittest.TestCase):
def test_the_tree_with_the_mutant_applied_is_the_code_cargo_mutants_tested_without_its_mark(self):
for diff, line in ((OPERATOR_DIFF, b" sum -= item;"), (BODY_DIFF, b" None")):
line_number, was, now = changed(diff)
planted = mutated(PICK, Mutant("src/pick.rs", line_number, "a name", was, now))
self.assertIn(line, planted.split(b"\n"))
self.assertNotIn(b"cargo-mutants", planted)
with self.subTest(line=line):
line_number, was, now = changed(diff)
planted = mutated(PICK, Mutant("src/pick.rs", line_number, "a name", was, now))
self.assertIn(line, planted.split(b"\n"))
self.assertNotIn(b"cargo-mutants", planted)
def test_keeps_an_unchanged_line_between_two_changed_ones_on_both_sides(self):
diff = b"--- a.rs\n+++ a name\n@@ -4,5 +4,4 @@\n fn f() {\n- a\n b\n- c\n+ d /* ~ changed by cargo-mutants ~ */\n }\n"
@@ -253,10 +254,15 @@ class KilledMutantsTest(unittest.TestCase):
self.assertIn("cargo-mutants said so", found.reason)
def test_outcomes_or_a_diff_that_cannot_be_read_are_a_failure_that_names_the_folder(self):
for outcomes, diffs in ((None, self.DIFFS), ({"outcomes": [{"summary": "CaughtMutant"}]}, self.DIFFS), ("no outcomes", self.DIFFS), (self.OUTCOMES, {})):
found = killed_mutants(self.top, ["src/pick.rs"], self.cargo_mutants(outcomes, diffs=diffs), 3)
self.assertIsInstance(found, Failure)
self.assertIn(f"could not read cargo-mutants' outcomes in {self.top}", found.reason)
for outcomes, diffs in (({"outcomes": [{"summary": "CaughtMutant"}]}, self.DIFFS), ("no outcomes", self.DIFFS), (self.OUTCOMES, {})):
with self.subTest(outcomes=outcomes, diffs=diffs):
found = killed_mutants(self.top, ["src/pick.rs"], self.cargo_mutants(outcomes, diffs=diffs), 3)
self.assertIsInstance(found, Failure)
self.assertIn(f"could not read cargo-mutants' outcomes in {self.top}", found.reason)
def test_finds_no_mutant_where_cargo_mutants_wrote_no_outcomes_as_it_does_where_it_finds_none(self):
self.assertEqual(killed_mutants(self.top, ["src/pick.rs"], self.cargo_mutants(None), 3), [])
self.assertEqual(list(pathlib.Path(self.top).iterdir()), [])
if __name__ == "__main__":