diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/architecture.rs | 19 | ||||
| -rw-r--r-- | tests/common/mod.rs | 8 | ||||
| -rw-r--r-- | tests/failure_modes.rs | 2 |
3 files changed, 22 insertions, 7 deletions
diff --git a/tests/architecture.rs b/tests/architecture.rs index b8de0ce..3eafcdc 100644 --- a/tests/architecture.rs +++ b/tests/architecture.rs @@ -883,6 +883,11 @@ fn the_dead_code_allowlist_names_real_items() { /// declaration. A type whose name nobody writes is still used if a field or /// method of it is: `Web::raw_request` hands back a `Raw` no test names, and /// reading `.status` off it is a use of the type. +/// +/// Private items are checked too. The blanket allowance in `tests/common` +/// excuses a private helper exactly as thoroughly as a public one, and a +/// private helper called by nothing is the harder case to notice, not the +/// easier one. #[test] fn the_test_helpers_are_used() { let common = root().join("tests/common/mod.rs"); @@ -895,9 +900,15 @@ fn the_test_helpers_are_used() { let lines: Vec<&str> = text.lines().collect(); let mut unused = Vec::new(); for (i, line) in lines.iter().enumerate() { + // `pub` and private alike: the blanket `allow(dead_code)` at the top of + // the file excuses both, so a private helper nobody calls is exactly as + // dead as a public one, and just as invisible to the compiler here. let t = line.trim_start(); - let Some(rest) = t.strip_prefix("pub ") else { continue }; - let rest = rest.trim_start(); + let indent = line.len() - t.len(); + if indent > 4 { + continue; + } + let rest = t.strip_prefix("pub ").unwrap_or(t); let Some(kind) = ["fn ", "struct ", "enum ", "const ", "static ", "type ", "trait "] .into_iter() .find(|k| rest.starts_with(k)) @@ -909,7 +920,9 @@ fn the_test_helpers_are_used() { continue; } // Everything this declaration introduces, minus the declaration itself. - let mut corpus = others.replace(&format!("pub {kind}{name}"), ""); + let mut corpus = others + .replace(&format!("pub {kind}{name}"), "") + .replace(&format!("{kind}{name}"), ""); if kind != "fn " { // Members of a struct or enum count as uses of the type. let mut depth = 0; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 0b46aeb..35aad9b 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,7 +1,9 @@ // Every test binary compiles this file, so a helper that one of them uses is -// dead code in the other twenty and the lint would fire everywhere and mean -// nothing. `the_test_helpers_are_used` in tests/architecture.rs is the check -// that does matter: a helper no test names is deleted, not excused. +// dead code in the other twenty — 46 of the items below warn that way, and an +// item-scoped allowance on each would say the same thing 46 times. The check +// that does the work is `the_test_helpers_are_used` in tests/architecture.rs: +// it reads this file and fails on any item, `pub` or private, that no test +// names, so the allowance hides noise and cannot hide dead weight. #![allow(dead_code)] use std::collections::HashMap; diff --git a/tests/failure_modes.rs b/tests/failure_modes.rs index e9083a2..4e7446a 100644 --- a/tests/failure_modes.rs +++ b/tests/failure_modes.rs @@ -31,7 +31,7 @@ impl SandboxBackend for FakeBackend { Ok(Arc::new(FakeSandbox { inner, fault: self.fault })) } fn status(&self) -> Result<Vec<SandboxInfo>> { - Ok(vec![SandboxInfo { id: "fake".into(), profile: "fake".into(), warm: true }]) + Ok(vec![SandboxInfo { id: "fake".into(), profile: "fake".into() }]) } } |
