Skip to content

Commit

Permalink
[site] expand test coverage instructions
Browse files Browse the repository at this point in the history
Fixes #1080.
  • Loading branch information
sunshowers committed Oct 31, 2023
1 parent 1f98ee6 commit 8980561
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions site/src/book/test-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,43 @@ Install Rust with the `llvm-tools-preview` component, nextest, and llvm-cov in G
run: cargo llvm-cov nextest
```
[See this in practice with nextest's own CI.](https://github.com/nextest-rs/nextest/blob/main/.github/workflows/coverage.yml)
### Collecting coverage data from doctests
> TODO: provide instructions for other report forms like HTML, and for reporting to an external code coverage service.
Nextest doesn't currently support doctests, so coverage data from nextest must be [merged](https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#merge-coverages-generated-under-different-test-conditions) with doctest data.
Here's an example GitHub Actions configuration:
```yaml
# Nightly Rust is required for cargo llvm-cov --doc.
- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: taiki-e/install-action@nextest

- name: Collect coverage data (including doctests)
run: |
cargo llvm-cov --no-report nextest
cargo llvm-cov --no-report --doc
cargo llvm-cov report --doctests --lcov --output-path lcov.info
```
### Reporting to an external coverage service
External services like [Codecov.io](https://about.codecov.io/) can be used to collect and display coverage data. Codecov is free for open source projects, and supports `lcov.info` files.

After generating an `lcov.info` file, upload it to Codecov with:

```yaml
- name: Upload coverage data to codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
```

### Example

Nextest itself uses the above mechanisms to collect coverage for its project. The config is located in [`.github/workflows/coverage.yml`](https://github.com/nextest-rs/nextest/blob/main/.github/workflows/coverage.yml).

## Integrating nextest into coverage tools

Expand Down

0 comments on commit 8980561

Please sign in to comment.