Expand description
ct-survey’s format-contextualized codebase survey.
Where crate::tree reports file-generic line/word/character counts over any
tree, ct-survey reports them bucketed by the units a build system defines
— for Rust, the workspace → crate → module hierarchy. The honesty classes are
kept distinct and carried into the output so they are never silently conflated:
- authoritative — crate identity, workspace membership, and cargo target
kinds, read from
cargo metadata(the same mechanismcrate::depsuses); - exact — file, line, word, and character counts;
- heuristic — the module bucketing (via
crate::modgraph::module_name) and the#[test]tally, which a scan approximates rather than proves.
The pure pieces here (metadata parse, the test scan, the roll-up, rendering)
are doctested; src/bin/ct-survey.rs is the thin IO shell that walks the
filesystem and drives them.
Structs§
- Counts
- A rolled-up count block (a crate’s or a module’s).
- Crate
Node - One crate node in the survey graph.
- File
Stat - One walked source file’s contribution: its path relative to the crate’s
source root (
Nonewhen it lies outside that root, e.g. an integration test undertests/), its exact counts, and its heuristic test tally. - Metadata
- The parsed subset of
cargo metadata: packages by id, workspace member ids, and the workspace root directory. - Module
Node - One module node in the survey graph.
- PkgMeta
- One package as
cargo metadatareports it (the subset a survey needs). - Survey
- A complete survey graph.
- Target
- One cargo target within a package.
Enums§
- Depth
- How deep the survey graph descends.
- Group
Kind - Which contextual group type frames a survey.
- SortKey
- Sort key for crates and, within each crate, its modules.
Functions§
- count_
tests - Heuristic count of test functions in a Rust source: attributes whose final
path segment is
test—#[test],#[tokio::test],#[test_case::test], and the like. A comprehension aid, not a parser: it does not discount attributes inside strings or comments, and#[cfg(test)](a module gate, not a test) is deliberately excluded. Always reported as a heuristic value. - infer_
group - Infer the contextual group type from a
Cargo.toml’s text: a manifest that declares a[workspace]table is aGroupKind::CargoWorkspace, otherwise aGroupKind::CargoCrate. This probes only the provided manifest — the authoritative member and target data still comes fromcargo metadata. - parse_
metadata - Parse
cargo metadata --format-version 1JSON into the surveyMetadata. Errors on malformed JSON or a missingpackages/workspace_membersarray — a defective read, never a silent empty survey. - render_
text - Render the survey as indented text. Heuristic values (test counts) wear a
trailing
~; a closing legend explains the marks. - roll_up
- Roll a crate’s
FileStats into whole-crateCounts(every file) plus a per-module breakdown (only files under the source root, bucketed bymodule_name), the modules sorted by name. The whole-crate total can exceed the module sum: files outside the source root (integration tests, benches) count toward the crate but belong to no module. - to_json
- The survey as a structured JSON value, each metric block tagged with the honesty class it belongs to (so an exact line count is never read as a heuristic test count).
- totals
- The whole-survey totals: rolled-up
Countsplus authoritative test- and bench-target counts across every crate.