diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/architecture-budget.json | 150 | ||||
| -rw-r--r-- | tests/architecture.rs | 28 |
2 files changed, 113 insertions, 65 deletions
diff --git a/tests/architecture-budget.json b/tests/architecture-budget.json index f451680..7a95341 100644 --- a/tests/architecture-budget.json +++ b/tests/architecture-budget.json @@ -1,5 +1,25 @@ { "dead_code": { + "allowlist": { + "db.Migration": "the row type of `MIGRATIONS`, which is `pub` only under `test-support`; production walks the table through `db::migrate` without naming it", + "db.PackageRow": "what `index_packages` hands back to `http`, the publish step and the `aur-build` binary, which bind it without naming it", + "db.Subscription": "what `get_subscription` and `list_subscriptions` hand back to `watch`, `usecase`, the binary and tests/detect.rs", + "db.Unbuilt": "the attention row `approved_but_unbuilt` returns to the web UI and to tests/crash.rs", + "pkginfo.Installed": "what `parse_installed` answers with, read line by line by `pipeline` and tests/world.rs", + "pkginfo.PkgInfo": "what `parse_pkginfo` answers with; `pipeline`, `shims` and tests/world.rs read its fields, never its name", + "review.BulkItem": "one outcome of `approve::bulk`, which tests/approve.rs drives directly", + "sandbox.ProvisionRequest": "the argument of `Provisioner::provision`, the trait the public `LocalAgentProvisioner` implements", + "sandbox.Provisioner": "implemented by the test-gated public `LocalAgentProvisioner`; a private trait on a public impl is E0445", + "shims.FakeInstalled": "the whole `shims` module is `test-support`-gated, so a release build never compiles it", + "shims.FakePackage": "the whole `shims` module is `test-support`-gated, so a release build never compiles it", + "shims.Manifest": "returned by `manifest()`, which the shim tests read; the module is `test-support`-gated", + "time.VirtualClock": "lives in the `test-support`-gated clock module, behind the gated `virtualize()` that returns it", + "usecase.Checked": "what `usecase::detect` returns to the `aur-build` binary, which is a separate crate", + "usecase.GcPlan": "what `usecase::plan_gc` returns to the `aur-build` binary, which is a separate crate", + "usecase.Prepared": "what `prepare_review` and `view_review` return to the `aur-build` binary, which is a separate crate", + "watch.CheckReport": "what `detect::check_pkgbase` returns; the test tier drives it and binds the value without naming it", + "watch.StageA": "what `upstream::probe` returns; tests/ops.rs and tests/vcs.rs call `probe` directly" + }, "deadonly": { "bin/gpg": 0, "bin/makechrootpkg": 0, @@ -9,26 +29,26 @@ "bin/repo-add": 0, "bin/sandbox-agent": 0, "config": 0, - "db": 8, + "db": 0, "error": 0, - "fetch": 1, + "fetch": 0, "git": 0, "hash": 0, - "http": 3, + "http": 0, "lib": 0, "main": 0, - "ops": 1, + "ops": 0, "pipeline": 0, - "pkginfo": 2, + "pkginfo": 0, "pkgver": 0, "recipe": 0, - "review": 1, - "sandbox": 2, - "shims": 8, - "time": 2, + "review": 0, + "sandbox": 0, + "shims": 0, + "time": 0, "urlutil": 0, - "usecase": 3, - "watch": 4 + "usecase": 0, + "watch": 0 } }, "modules": { @@ -121,14 +141,14 @@ "test": 2 }, "db": { - "dead": 19, - "deadonly": 8, + "dead": 11, + "deadonly": 0, "glob": 0, "largest": 368, "largest_file": "src/db/mod.rs", - "lines": 3923, - "priv": 12, - "pub": 196, + "lines": 3897, + "priv": 19, + "pub": 189, "test": 11 }, "error": { @@ -143,14 +163,14 @@ "test": 0 }, "fetch": { - "dead": 1, - "deadonly": 1, + "dead": 0, + "deadonly": 0, "glob": 0, "largest": 57, "largest_file": "src/fetch.rs", "lines": 57, - "priv": 1, - "pub": 2, + "priv": 2, + "pub": 1, "test": 0 }, "git": { @@ -176,14 +196,14 @@ "test": 0 }, "http": { - "dead": 8, - "deadonly": 3, + "dead": 5, + "deadonly": 0, "glob": 0, "largest": 565, "largest_file": "src/http/routes/pages.rs", "lines": 2034, - "priv": 78, - "pub": 20, + "priv": 81, + "pub": 17, "test": 5 }, "lib": { @@ -209,14 +229,14 @@ "test": 0 }, "ops": { - "dead": 4, - "deadonly": 1, + "dead": 3, + "deadonly": 0, "glob": 0, "largest": 455, "largest_file": "src/ops.rs", "lines": 455, - "priv": 3, - "pub": 13, + "priv": 5, + "pub": 11, "test": 3 }, "pipeline": { @@ -231,12 +251,12 @@ "test": 6 }, "pkginfo": { - "dead": 2, - "deadonly": 2, + "dead": 0, + "deadonly": 0, "glob": 0, - "largest": 115, + "largest": 117, "largest_file": "src/pkginfo.rs", - "lines": 115, + "lines": 117, "priv": 0, "pub": 6, "test": 0 @@ -264,47 +284,47 @@ "test": 0 }, "review": { - "dead": 5, - "deadonly": 1, + "dead": 4, + "deadonly": 0, "glob": 0, "largest": 301, "largest_file": "src/review/diff.rs", - "lines": 914, + "lines": 915, "priv": 4, "pub": 24, "test": 4 }, "sandbox": { - "dead": 9, - "deadonly": 2, + "dead": 7, + "deadonly": 0, "glob": 0, - "largest": 506, + "largest": 508, "largest_file": "src/sandbox/kata.rs", - "lines": 1411, + "lines": 1413, "priv": 16, "pub": 21, "test": 7 }, "shims": { - "dead": 12, - "deadonly": 8, + "dead": 4, + "deadonly": 0, "glob": 0, - "largest": 652, + "largest": 655, "largest_file": "src/shims/mod.rs", - "lines": 652, - "priv": 8, - "pub": 13, + "lines": 655, + "priv": 13, + "pub": 8, "test": 4 }, "time": { - "dead": 5, - "deadonly": 2, + "dead": 3, + "deadonly": 0, "glob": 0, - "largest": 242, + "largest": 243, "largest_file": "src/time.rs", - "lines": 242, + "lines": 243, "priv": 0, - "pub": 14, + "pub": 13, "test": 3 }, "urlutil": { @@ -319,25 +339,25 @@ "test": 0 }, "usecase": { - "dead": 3, - "deadonly": 3, + "dead": 0, + "deadonly": 0, "glob": 0, - "largest": 123, + "largest": 124, "largest_file": "src/usecase/reviews.rs", - "lines": 402, + "lines": 405, "priv": 0, "pub": 30, "test": 0 }, "watch": { - "dead": 8, - "deadonly": 4, + "dead": 4, + "deadonly": 0, "glob": 0, - "largest": 302, + "largest": 296, "largest_file": "src/watch/upstream.rs", - "lines": 1121, - "priv": 10, - "pub": 24, + "lines": 1115, + "priv": 12, + "pub": 21, "test": 4 } }, @@ -348,15 +368,15 @@ "total": 36 }, "totals": { - "dead": 84, - "deadonly": 35, + "dead": 49, + "deadonly": 0, "edges": 87, "glob": 0, "largest": 701, "largest_file": "src/config.rs", - "lines": 15704, - "priv": 150, - "pub": 470, + "lines": 15684, + "priv": 170, + "pub": 448, "test": 49 } } 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"); |
