# 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.

- Skill: `majiayu000/cargo-coverage` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/cargo-coverage`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/cargo-coverage/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/cargo-coverage

---


# 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.

