Answer review: keep Rust test modules for bugs only, order imports, reword
CI / tests (pull_request) Has been cancelled

This commit is contained in:
2026-11-26 01:30:46 +01:00
parent 347368040e
commit cecabf324a
6 changed files with 49 additions and 33 deletions
+7 -7
View File
@@ -43,21 +43,21 @@ class ModulesTest(unittest.TestCase):
def test_holds_each_test_module_from_its_attribute_to_its_closing_brace(self):
self.assertEqual(spelt(LIB), {"tests": LIB[LIB.index("#[cfg(test)]"):LIB.rindex("}") + 1]})
def test_holds_none_where_the_file_has_no_test_module(self):
def test_lists_no_module_where_the_file_has_no_test_module(self):
self.assertEqual(modules("fn main() {}\n"), {})
def test_takes_a_module_with_a_visibility_and_another_attribute(self):
source = "#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks {\n}\nfn after() {}\n"
self.assertEqual(spelt(source), {"checks": source[:source.index("}") + 1]})
def test_leaves_out_what_the_attribute_is_not_on_an_inline_module(self):
def test_lists_no_module_where_the_attribute_is_on_anything_but_an_inline_module(self):
self.assertEqual(modules("#[cfg(test)]\nmod tests;\n#[cfg(test)]\nuse std::fmt;\n#[cfg(test)]\nfn helper() {}\n"), {})
def test_leaves_out_a_module_inside_a_module(self):
def test_lists_no_module_inside_a_test_module(self):
source = "#[cfg(test)]\nmod outer {\n #[cfg(test)]\n mod inner {}\n}\n"
self.assertEqual(list(spelt(source)), ["outer"])
def test_reads_past_a_brace_in_a_string_a_char_or_a_comment(self):
def test_reads_past_a_brace_in_a_string_a_char_a_comment_or_an_escape(self):
source = textwrap.dedent("""\
#[cfg(test)]
mod tests {
@@ -87,7 +87,7 @@ class ModulesTest(unittest.TestCase):
source = "#[cfg(test)]\nmod tests {\n const A: &str = " + literal + ";\n}\nfn after() {}\n"
self.assertEqual(list(spelt(source)), ["tests"])
def test_leaves_out_a_module_a_comment_or_a_char_stands_before(self):
def test_lists_no_plain_module_that_follows_a_comment_or_a_char(self):
self.assertEqual(modules("// helpers\nmod util {}\nfn a() { let c = 'x'; }\nmod more {}\n"), {})
def test_lists_a_test_module_inside_a_module_that_is_no_test(self):
@@ -104,7 +104,7 @@ class ModulesTest(unittest.TestCase):
class TellsApartTest(unittest.TestCase):
def test_tells_a_rust_file_apart_where_its_modules_can_be(self):
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])
def test_takes_a_file_of_another_language_whatever_it_holds(self):
@@ -132,7 +132,7 @@ class WithTestsOfTest(unittest.TestCase):
fixed = "fn a() { 2 }\n#[cfg(test)]\nmod y { fn changed() {} }\n#[cfg(test)]\nmod x { fn changed() {} }\nfn c() {}\n"
self.assertEqual(with_tests_of(planted, fixed), "fn a() { 2 }\n#[cfg(test)]\nmod y { fn u() {} }\n#[cfg(test)]\nmod x { fn t() {} }\nfn c() {}\n")
def test_puts_the_planted_modules_in_where_their_names_sort_in_file_order(self):
def test_puts_in_planted_modules_whose_length_differs_from_the_fixed_ones(self):
planted = "#[cfg(test)]\nmod a { 1 }\n#[cfg(test)]\nmod b { 22 }\nfn code() {}\n"
fixed = "#[cfg(test)]\nmod a { 333 }\n#[cfg(test)]\nmod b { 4444444 }\nfn fixed() {}\n"
self.assertEqual(with_tests_of(planted, fixed), "#[cfg(test)]\nmod a { 1 }\n#[cfg(test)]\nmod b { 22 }\nfn fixed() {}\n")