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

  1. Run tests with coverage enabled first (see cargo-test skill).
  2. Execute skills/cargo-coverage/scripts/run_coverage.sh from repository root.
  3. Review the coverage table output showing per-file statistics.

Workflow

  1. Generate coverage data: Run tests with cargo llvm-cov nextest or cargo llvm-cov test.
  2. Extract report: cargo llvm-cov report --json --summary-only outputs coverage in JSON format.
  3. Format output: Pipe through jq and xan to create readable tables.
  4. Environment:
    • NO_COLOR=1 - Disables color output
    • CARGO_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=1 for 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 jq and xan via package manager or cargo.
  • Path errors: Ensure running from repository root directory.

Didn't find tool you were looking for?

Be as detailed as possible for better results