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:
2026-11-27 17:43:33 +01:00
parent f5940f265d
commit 814779c9a1
4 changed files with 26 additions and 14 deletions
+12 -2
View File
@@ -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)