Skip to content

Commit

Permalink
Accept --doctests for show-env and report
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 30, 2023
1 parent 92cf175 commit 5289e9e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Support `--doctests` flag in `cargo llvm-cov report` and `cargo llvm-cov show-env`.

## [0.5.35] - 2023-10-18

- Improve compile time.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ cargo llvm-cov --no-report --features b
cargo llvm-cov report --lcov # generate report without tests
```

Note: To include coverage for doctests you also need to pass `--doctests` to `cargo llvm-cov report`.

### Get coverage of C/C++ code linked to Rust library/binary

Set `CC`, `CXX`, `LLVM_COV`, and `LLVM_PROFDATA` environment variables to Clang/LLVM compatible with the LLVM version used in rustc, and run cargo-llvm-cov with `--include-ffi` flag.
Expand Down Expand Up @@ -445,6 +447,8 @@ cargo llvm-cov report --lcov # Generate report without tests.

Note: cargo-llvm-cov subcommands other than `report` and `clean` may not work correctly in the context where environment variables are set by `show-env`; consider using normal `cargo`/`cargo-nextest` commands.

Note: To include coverage for doctests you also need to pass `--doctests` to both `cargo llvm-cov show-env` and `cargo llvm-cov report`.

### Exclude file from coverage

To exclude specific file patterns from the report, use the `--ignore-filename-regex` option.
Expand Down
6 changes: 6 additions & 0 deletions docs/cargo-llvm-cov-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ OPTIONS:
--include-build-script
Include build script in coverage report

--doctests
Including doc tests (unstable)

This flag is unstable. See <https://github.com/taiki-e/cargo-llvm-cov/issues/2> for
more.

-q, --quiet
Display one character per test instead of one line

Expand Down
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ impl Args {
let flag = if doc { "--doc" } else { "--doctests" };
match subcommand {
Subcommand::None | Subcommand::Test => {}
Subcommand::ShowEnv | Subcommand::Report if doctests => {}
Subcommand::Nextest => bail!("doctest is not supported for nextest"),
_ => unexpected(flag, subcommand)?,
}
Expand Down
10 changes: 6 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,12 @@ fn invalid_arg() {
.arg("--doc")
.assert_failure()
.stderr_contains("invalid option '--doc'");
cargo_llvm_cov(subcommand)
.arg("--doctests")
.assert_failure()
.stderr_contains("invalid option '--doctests'");
if subcommand != "show-env" {
cargo_llvm_cov(subcommand)
.arg("--doctests")
.assert_failure()
.stderr_contains("invalid option '--doctests'");
}
}
}
if !matches!(subcommand, "" | "nextest") {
Expand Down

0 comments on commit 5289e9e

Please sign in to comment.