Agent skill
cargo-coverage
Generate per-file coverage reports using cargo llvm-cov with formatted output. Requires tests to run first with coverage enabled. Trigger when asked for code coverage metrics or reports.
Stars
163
Forks
31
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/cargo-coverage
SKILL.md
Cargo Coverage
Overview
Generate detailed, per-file coverage reports using cargo llvm-cov with JSON output formatted into readable tables. Provides function, line, and region coverage percentages.
Quick Start
- Run tests with coverage enabled first (see
cargo-testskill). - Execute
skills/cargo-coverage/scripts/run_coverage.shfrom repository root. - Review the coverage table output showing per-file statistics.
Workflow
- Generate coverage data: Run tests with
cargo llvm-cov nextestorcargo llvm-cov test. - Extract report:
cargo llvm-cov report --json --summary-onlyoutputs coverage in JSON format. - Format output: Pipe through
jqandxanto create readable tables. - Environment:
NO_COLOR=1- Disables color outputCARGO_TERM_COLOR=never- Ensures cargo output is colorless
Coverage Metrics
- Functions: Percentage of functions executed during tests
- Lines: Percentage of code lines covered
- Regions: Percentage of code regions (branches, conditionals) covered
Best Practices
- Run tests first: Coverage data is generated by running tests with instrumentation.
- Use colorless output: Keep
NO_COLOR=1for CI/log parsing. - Workspace scope: Report includes all workspace members.
- Run from root: Execute from repository root for correct file path resolution.
- Rerun after changes: Regenerate coverage after modifying tests or source code.
Common Commands
Generate and view coverage report
bash
cargo llvm-cov nextest --workspace --all-features
cargo llvm-cov report --json --summary-only | jq
Coverage with specific format
bash
cargo llvm-cov report --lcov --output-path coverage.lcov
cargo llvm-cov report --html
Failure Handling
- No coverage data: Run tests with coverage enabled first.
- Missing tools: Install
jqandxanvia package manager or cargo. - Path errors: Ensure running from repository root directory.
Didn't find tool you were looking for?