0.0.5-alpha.5.fix.1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# file: tests/test_rust_export_completeness.py
|
||||
# version: 1
|
||||
# version: 2
|
||||
|
||||
"""Regression tests for the optional Rust crate-root façade audit."""
|
||||
|
||||
@@ -105,6 +105,133 @@ class RustExportCompletenessTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(self.candidates(), [])
|
||||
|
||||
|
||||
def test_bare_reference_in_declaration_module_is_rejected(self) -> None:
|
||||
self.crate(
|
||||
"crates/example-lib",
|
||||
"mod api;\npub use self::api::Thing;\n",
|
||||
{
|
||||
"src/api.rs": (
|
||||
"pub struct Thing;\n"
|
||||
"impl Thing {\n"
|
||||
" pub fn make() -> Thing { return Thing; }\n"
|
||||
"}\n"
|
||||
),
|
||||
},
|
||||
)
|
||||
candidates = [candidate for candidate in self.candidates() if candidate.code == "RUST-IMPORT-201"]
|
||||
self.assertEqual(len(candidates), 2)
|
||||
self.assertTrue(all("crate::Thing" in candidate.message for candidate in candidates))
|
||||
|
||||
def test_crate_root_reference_in_declaration_module_is_clean(self) -> None:
|
||||
self.crate(
|
||||
"crates/example-lib",
|
||||
"mod api;\npub use self::api::Thing;\n",
|
||||
{
|
||||
"src/api.rs": (
|
||||
"pub struct Thing;\n"
|
||||
"impl crate::Thing {\n"
|
||||
" pub fn make() -> crate::Thing { return crate::Thing; }\n"
|
||||
"}\n"
|
||||
),
|
||||
},
|
||||
)
|
||||
self.assertEqual(self.candidates(), [])
|
||||
|
||||
def test_import_then_bare_reference_is_rejected(self) -> None:
|
||||
self.crate(
|
||||
"crates/example-lib",
|
||||
"mod api;\nmod consumer;\npub use self::api::Thing;\n",
|
||||
{
|
||||
"src/api.rs": "pub struct Thing;\n",
|
||||
"src/consumer.rs": "use crate::Thing;\npub(crate) fn make() -> Thing { return Thing; }\n",
|
||||
},
|
||||
)
|
||||
candidates = [candidate for candidate in self.candidates() if candidate.code == "RUST-IMPORT-201"]
|
||||
self.assertEqual(len(candidates), 1)
|
||||
|
||||
def test_self_super_and_internal_module_paths_are_rejected(self) -> None:
|
||||
self.crate(
|
||||
"crates/example-lib",
|
||||
"mod api;\nmod consumer;\npub use self::api::Thing;\n",
|
||||
{
|
||||
"src/api.rs": "pub struct Thing;\n",
|
||||
"src/consumer.rs": (
|
||||
"pub(crate) fn a() -> crate::api::Thing { return crate::api::Thing; }\n"
|
||||
"pub(crate) fn b() -> api::Thing { todo!() }\n"
|
||||
),
|
||||
},
|
||||
)
|
||||
candidates = [candidate for candidate in self.candidates() if candidate.code == "RUST-IMPORT-201"]
|
||||
self.assertEqual(len(candidates), 2)
|
||||
|
||||
def test_attached_unit_test_visible_item_uses_crate_root(self) -> None:
|
||||
self.crate(
|
||||
"crates/example-lib",
|
||||
"mod api;\npub use self::api::Thing;\n",
|
||||
{
|
||||
"src/api.rs": (
|
||||
"pub struct Thing;\n"
|
||||
"#[cfg(test)]\n"
|
||||
"#[path = \"../unit_tests/api_tests.rs\"]\n"
|
||||
"mod tests;\n"
|
||||
),
|
||||
"unit_tests/api_tests.rs": "fn make() -> super::Thing { return super::Thing; }\n",
|
||||
},
|
||||
)
|
||||
candidates = [candidate for candidate in self.candidates() if candidate.code == "RUST-IMPORT-201"]
|
||||
self.assertEqual(len(candidates), 1)
|
||||
|
||||
def test_private_parent_item_in_attached_test_is_not_owned_by_this_audit(self) -> None:
|
||||
self.crate(
|
||||
"crates/example-lib",
|
||||
"mod api;\n",
|
||||
{
|
||||
"src/api.rs": (
|
||||
"fn helper() -> u8 { return 1; }\n"
|
||||
"#[cfg(test)]\n"
|
||||
"#[path = \"../unit_tests/api_tests.rs\"]\n"
|
||||
"mod tests;\n"
|
||||
),
|
||||
"unit_tests/api_tests.rs": "fn value() -> u8 { return super::helper(); }\n",
|
||||
},
|
||||
)
|
||||
self.assertEqual(self.candidates(), [])
|
||||
|
||||
def test_external_qualified_same_named_item_is_not_misclassified(self) -> None:
|
||||
self.crate(
|
||||
"crates/example-lib",
|
||||
"mod api;\nmod consumer;\npub use self::api::Result;\n",
|
||||
{
|
||||
"src/api.rs": "pub struct Result;\n",
|
||||
"src/consumer.rs": "pub(crate) fn value() -> external_crate::Result { todo!() }\n",
|
||||
},
|
||||
)
|
||||
self.assertEqual(self.candidates(), [])
|
||||
|
||||
def test_method_with_same_name_as_public_function_is_not_misclassified(self) -> None:
|
||||
self.crate(
|
||||
"crates/example-lib",
|
||||
"mod api;\nmod consumer;\npub use self::api::run;\n",
|
||||
{
|
||||
"src/api.rs": "pub fn run() -> u8 { return 1; }\n",
|
||||
"src/consumer.rs": "pub(crate) fn value(service: &Service) -> u8 { return service.run(); }\nstruct Service;\nimpl Service { fn run(&self) -> u8 { return 2; } }\n",
|
||||
},
|
||||
)
|
||||
self.assertEqual(self.candidates(), [])
|
||||
|
||||
def test_lib_and_main_targets_are_not_conflated(self) -> None:
|
||||
crate = self.crate(
|
||||
"crates/example-app",
|
||||
"mod api;\npub use self::api::Thing;\n",
|
||||
{"src/api.rs": "pub struct Thing;\n"},
|
||||
)
|
||||
(crate / "src/main.rs").write_text(
|
||||
"fn main() { let _ = fixture::Thing; }\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
self.assertEqual(self.candidates(), [])
|
||||
|
||||
def test_cli_status_for_clean_violation_report_only_and_missing_crates(self) -> None:
|
||||
script = pathlib.Path(__file__).resolve().parents[1] / "scripts" / "audit_rust_export_completeness.py"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user