Keep a Rust test in a file of its own as planted in a task-bench fix
This commit is contained in:
@@ -103,6 +103,30 @@ class ModulesTest(unittest.TestCase):
|
||||
self.assertIsNone(modules(source))
|
||||
|
||||
|
||||
def declared(source: str) -> list[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"])
|
||||
|
||||
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"), [])
|
||||
|
||||
def test_leaves_out_a_declaration_in_a_comment_or_a_string(self):
|
||||
source = '// #[cfg(test)]\n// mod a;\n/* #[cfg(test)] mod b; */\nconst C: &str = "#[cfg(test)] mod c;";\nconst D: &str = r#"#[cfg(test)] mod d;"#;\n'
|
||||
self.assertEqual(declared(source), [])
|
||||
|
||||
def test_cannot_tell_where_a_declaration_moves_its_file_with_a_path_attribute(self):
|
||||
self.assertIsNone(declared('#[cfg(test)]\n#[path = "elsewhere.rs"]\nmod tests;\n'))
|
||||
|
||||
def test_cannot_tell_where_a_string_or_comment_is_never_closed(self):
|
||||
for source in ("#[cfg(test)]\nmod tests;\nconst A: &str = \"\n", "/* open\n#[cfg(test)]\nmod tests;\n"):
|
||||
with self.subTest(source=source):
|
||||
self.assertIsNone(declared(source))
|
||||
|
||||
|
||||
class TellsApartTest(unittest.TestCase):
|
||||
def test_tells_the_modules_of_a_rust_file_apart_where_they_can_be(self):
|
||||
self.assertEqual([tells_apart("lib.rs", b"fn a() {}"), tells_apart("lib.rs", b"fn a() {")], [True, False])
|
||||
|
||||
Reference in New Issue
Block a user