Answer stability round 2: 0 🔴, 1 🟡 (0 misread); compare each test declaration's whole text, so an attribute a fix adds to it counts as a change
This commit is contained in:
@@ -41,7 +41,7 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream.
|
||||
`src/pick-test.js`, 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 or declaration of the planted file's, or the planted file has inline modules and Haiku's cannot be
|
||||
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
|
||||
Haiku's cannot be told apart, Haiku's stands. A Rust mutant
|
||||
whose file's modules cannot be told apart, as where two share a name or a brace, string or comment is never closed, is passed
|
||||
|
||||
@@ -219,10 +219,10 @@ def rust_test_files(tree: str) -> set[str] | None:
|
||||
for path in sorted(files):
|
||||
if not path.endswith(".rs") or os.path.islink(os.path.join(tree, path)):
|
||||
continue
|
||||
names = declared(pathlib.Path(tree, path).read_bytes())
|
||||
if names is None:
|
||||
declarations = declared(pathlib.Path(tree, path).read_bytes())
|
||||
if declarations is None:
|
||||
return None
|
||||
for name in names:
|
||||
for name, _ in declarations:
|
||||
standing = files.intersection(homes(path, name))
|
||||
if not standing:
|
||||
return None
|
||||
|
||||
@@ -56,18 +56,19 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None:
|
||||
return found if depth == 0 and inside is None else None
|
||||
|
||||
|
||||
def declared(source: bytes) -> list[str] | None:
|
||||
"""The name of each `#[cfg(test)] mod name;` of source, in the order they stand. The module's code is in a file of its own. None where
|
||||
def declared(source: bytes) -> list[tuple[str, str]] | None:
|
||||
"""Each `#[cfg(test)] mod name;` of source, in the order they stand, as the module's name and the declaration's text from the
|
||||
`#[cfg(test)]` to the `;` with its spaces and newlines squeezed to one space. The module's code is in a file of its own. None where
|
||||
a string or comment is never closed."""
|
||||
names = []
|
||||
found = []
|
||||
position = 0
|
||||
while match := SCAN.search(source, position):
|
||||
if (after := after_token(source, match)) is None:
|
||||
return None
|
||||
position = after
|
||||
if match.group() == b"#[cfg(test)]" and (declaration := DECLARATION.match(source, position)):
|
||||
names.append(declaration.group("name").decode())
|
||||
return names
|
||||
found.append((declaration.group("name").decode(), " ".join(source[match.start():declaration.end()].decode().split())))
|
||||
return found
|
||||
|
||||
|
||||
def homes(path: str, name: str) -> list[str]:
|
||||
@@ -115,11 +116,12 @@ def with_tests_of(planted: bytes, copy: bytes) -> bytes:
|
||||
"""copy with each of its test modules replaced by the one of that name in planted, and each that planted lacks left out. So a test a
|
||||
fix changed, removed or added doesn't count.
|
||||
|
||||
Where copy lacks a `mod name;` declaration of planted's, or cannot have its declarations told apart, planted is returned: the file
|
||||
of that module stands as planted, and a fix that drops the declaration would leave its tests uncompiled. Otherwise, where planted's
|
||||
Where copy lacks a `mod name;` declaration of planted's, as written, or cannot have its declarations told apart, planted is
|
||||
returned: the file of that module stands as planted, and a fix that drops the declaration or adds an attribute such as `#[path]`
|
||||
to it would leave its tests uncompiled or unrun. Otherwise, where planted's
|
||||
modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where planted has some
|
||||
and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module to put them in."""
|
||||
if not set(declared(planted) or []) <= set(declared(copy) or []):
|
||||
if not {text for _, text in declared(planted) or []} <= {text for _, text in declared(copy) or []}:
|
||||
return planted
|
||||
before, after = modules(planted), modules(copy)
|
||||
# Haiku's file stands where planted's modules can't be told apart. The bench never plants a bug in such a file, and a guess at
|
||||
|
||||
@@ -103,13 +103,13 @@ class ModulesTest(unittest.TestCase):
|
||||
self.assertIsNone(modules(source))
|
||||
|
||||
|
||||
def declared(source: str) -> list[str] | None:
|
||||
def declared(source: str) -> list[tuple[str, str]] | None:
|
||||
return rust_test_modules.declared(source.encode())
|
||||
|
||||
|
||||
class DeclaredTest(unittest.TestCase):
|
||||
def test_lists_each_test_module_the_file_declares_without_a_body(self):
|
||||
self.assertEqual(declared("#[cfg(test)]\nmod tests;\n#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks;\n"), ["tests", "checks"])
|
||||
self.assertEqual(declared("#[cfg(test)]\nmod tests;\n#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks;\n"), [("tests", "#[cfg(test)] mod tests;"), ("checks", "#[cfg(test)] #[allow(dead_code)] pub(crate) mod checks;")])
|
||||
|
||||
def test_leaves_out_an_inline_module_and_a_declaration_that_is_no_test_module(self):
|
||||
self.assertEqual(declared(LIB + "mod util;\n#[cfg(feature = \"x\")]\nmod extra;\n"), [])
|
||||
@@ -147,6 +147,16 @@ class WithTestsOfTest(unittest.TestCase):
|
||||
with self.subTest(name):
|
||||
self.assertEqual(with_tests_of(planted, fixed), planted)
|
||||
|
||||
def test_takes_the_planted_file_where_the_fix_keeps_a_declaration_but_changes_it(self):
|
||||
planted = "fn a() { 1 }\n#[cfg(test)]\nmod tests;\n"
|
||||
for name, declaration in {"never compiled": "#[cfg(test)]\n#[cfg(any())]\nmod tests;", "another file": '#[cfg(test)]\n#[path = "empty.rs"]\nmod tests;', "renamed": "#[cfg(test)]\nmod other;"}.items():
|
||||
with self.subTest(name):
|
||||
self.assertEqual(with_tests_of(planted, f"fn a() {{ 2 }}\n{declaration}\n"), planted)
|
||||
|
||||
def test_takes_the_fixed_file_where_it_keeps_a_declaration_with_other_spacing(self):
|
||||
fixed = "fn a() { 2 }\n#[cfg(test)] mod tests;\n"
|
||||
self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed)
|
||||
|
||||
def test_takes_the_fixed_file_where_it_keeps_each_declaration_and_adds_one(self):
|
||||
fixed = "fn a() { 2 }\n#[cfg(test)]\nmod more;\n#[cfg(test)]\nmod tests;\n"
|
||||
self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed)
|
||||
|
||||
Reference in New Issue
Block a user