Skip to content

Instantly share code, notes, and snippets.

@deild
Last active December 28, 2020 21:16
Show Gist options
  • Select an option

  • Save deild/28907751af27c5476c72417de14f4b01 to your computer and use it in GitHub Desktop.

Select an option

Save deild/28907751af27c5476c72417de14f4b01 to your computer and use it in GitHub Desktop.
Rust Code Coverage Tools

grcov

Another tool for code coverage is called grcov. It is available at https://github.com/mozilla/grcov.

To produce HTML reports with grcov you can either use the built-in way or using the lcov package. The workflow for grcov is as follows:

# Install the tool
cargo install grcov

# Enable the required Rust flags to generate the coverage files
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off"
# add -Zno-landing-pads if not macos

# grcov requires rust nightly at this time
cargo +nightly test

# generate the html report
grcov ./target/debug/ -s . -t html --llvm --branch --ignore-not-existing -o ./target/debug/coverage/

# open the report 
open target/debug/coverage/index.html

It should produce a report like this for you:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment