diff options
Diffstat (limited to 'tests/architecture.rs')
| -rw-r--r-- | tests/architecture.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/architecture.rs b/tests/architecture.rs index 12de924..6f68f2b 100644 --- a/tests/architecture.rs +++ b/tests/architecture.rs @@ -241,6 +241,7 @@ impl Census { .collect(); let mut modules: BTreeMap<String, Module> = BTreeMap::new(); + let allowlist = allowed_pub_items(); for (path, text) in &texts { let module = modules.entry(module_of(path)).or_default(); module.lines += text.lines().count(); @@ -278,6 +279,12 @@ impl Census { } let used_by_tests = test_texts.iter().any(|t| mentions(t, name)); for module in declaring { + // An item the budget file argues for is a decision, not a hole, + // so it leaves the dead columns entirely. `deadonly` then means + // *dead and unargued* — the one number that can stay at zero. + if allowlist.contains(&format!("{module}.{name}")) { + continue; + } let module = modules.get_mut(module).unwrap(); module.dead += 1; if used_by_tests { @@ -340,6 +347,27 @@ impl Census { } } +/// The `dead_code.allowlist` keys — `module.item` for every item that stays +/// `pub` by decision, with its reason next to it in the same file. +fn allowed_pub_items() -> BTreeSet<String> { + let path = root().join("tests/architecture-budget.json"); + let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {}", path.display(), e)); + let value: serde_json::Value = serde_json::from_str(&text).expect("budget file is json"); + value + .get("dead_code") + .and_then(|d| d.get("allowlist")) + .and_then(|a| a.as_object()) + .map(|a| { + a.keys() + .map(|k| { + assert!(!k.trim().is_empty(), "an allowlist key cannot be blank"); + k.clone() + }) + .collect() + }) + .unwrap_or_default() +} + /// A top-level section of the budget file, as `key -> allowed`. fn budget_section(section: &str) -> BTreeMap<String, usize> { let path = root().join("tests/architecture-budget.json"); |
