Skip to main content

Module survey

Module survey 

Source
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 mechanism crate::deps uses);
  • 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).
CrateNode
One crate node in the survey graph.
FileStat
One walked source file’s contribution: its path relative to the crate’s source root (None when it lies outside that root, e.g. an integration test under tests/), 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.
ModuleNode
One module node in the survey graph.
PkgMeta
One package as cargo metadata reports 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.
GroupKind
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 a GroupKind::CargoWorkspace, otherwise a GroupKind::CargoCrate. This probes only the provided manifest — the authoritative member and target data still comes from cargo metadata.
parse_metadata
Parse cargo metadata --format-version 1 JSON into the survey Metadata. Errors on malformed JSON or a missing packages/workspace_members array — 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-crate Counts (every file) plus a per-module breakdown (only files under the source root, bucketed by module_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 Counts plus authoritative test- and bench-target counts across every crate.