cargo-llvm-cov

crates.io license rustc build status

[EXPERIMENTAL] A wrapper for source based code coverage (-Zinstrument-coverage, [rust-lang/rust#79121]).

Installation

cargo-llvm-cov currently requires llvm-tools-preview and rustfilt.

```sh cargo install cargo-llvm-cov --version 0.1.0-alpha.3

cargo install rustfilt

rustup component add llvm-tools-preview ```

Alternatively, download compiled binaries from GitHub Releases.

cargo-llvm-cov relies on unstable compiler flags so it requires a nightly toolchain to be installed, though does not require nightly to be the default toolchain or the one with which cargo-llvm-cov itself is executed. If the default toolchain is one other than nightly, running cargo llvm-cov will find and use nightly anyway.

Usage

A complete list of options

```console $ cargo llvm-cov --help cargo-llvm-cov A wrapper for source based code coverage (-Zinstrument-coverage)

USAGE: cargo llvm-cov [OPTIONS] [-- ...]

OPTIONS: --json Export coverage data in "json" format (the report will be printed to stdout).

        This internally calls `llvm-cov export -format=text`. See <https://llvm.org/docs/CommandGuide/llvm-
        cov.html#llvm-cov-export> for more.
    --lcov
        Export coverage data in "lcov" format (the report will be printed to stdout).

        This internally calls `llvm-cov export -format=lcov`. See <https://llvm.org/docs/CommandGuide/llvm-
        cov.html#llvm-cov-export> for more.
    --summary-only
        Export only summary information for each file in the coverage data.

        This flag can only be used together with either --json or --lcov.
    --text
        Generate coverage reports in “text” format (the report will be printed to stdout).

        This internally calls `llvm-cov show -format=text`. See <https://llvm.org/docs/CommandGuide/llvm-
        cov.html#llvm-cov-show> for more.
    --html
        Generate coverage reports in "html" format (the report will be generated in `target/llvm-cov` directory).

        This internally calls `llvm-cov show -format=html`. See <https://llvm.org/docs/CommandGuide/llvm-
        cov.html#llvm-cov-show> for more.
    --open
        Generate coverage reports in "html" format and open them in a browser after the operation

    --output-dir <output-dir>
        Specify a directory to write coverage reports into (default to `target/llvm-cov`).

        This flag can only be used together with --text, --html, or --open.
    --doctests
        Including doc tests (unstable)

    --workspace
        Test all packages in the workspace [aliases: all]

    --exclude <SPEC>...
        Exclude packages from the test

    --release
        Build artifacts in release mode, with optimizations

    --features <FEATURES>...
        Space or comma separated list of features to activate

    --all-features
        Activate all available features

    --no-default-features
        Do not activate the `default` feature

    --target <TRIPLE>
        Build for the target triple

    --manifest-path <PATH>
        Path to Cargo.toml

-h, --help
        Prints help information

-V, --version
        Prints version information

ARGS: ... Arguments for the test binary ```

By default, only the summary is displayed in the terminal.

sh cargo llvm-cov

With html report (the report will be generated to target/llvm-cov directory):

sh cargo llvm-cov --html open target/llvm-cov/index.html

or

sh cargo llvm-cov --open

With plain text report (the report will be printed to stdout):

sh cargo llvm-cov --text | less -R

With json report (the report will be printed to stdout):

sh cargo llvm-cov --json

With lcov report (the report will be printed to stdout):

sh cargo llvm-cov --lcov

Known limitations

See also the coverage-related issues reported in rust-lang/rust.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.