Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Latest commit

 

History

History
48 lines (32 loc) · 1.41 KB

unit_test_coverage.md

File metadata and controls

48 lines (32 loc) · 1.41 KB

source coded coverage

grcov has a bug in Windows, please run the command line with administrator

bug issues

First of all, install grcov

cargo install grcov

Second, install the llvm-tools Rust component (llvm-tools-preview for now, it might become llvm-tools soon):

rustup component add llvm-tools-preview

Generate source-based coverage

# Export the flags needed to instrument the program to collect code coverage.
export RUSTFLAGS="-Zinstrument-coverage"

# Ensure each test runs gets its own profile information by defining the LLVM_PROFILE_FILE environment variable (%p will be replaced by the process ID, and %m by the binary signature):
export LLVM_PROFILE_FILE="your_name-%p-%m.profraw"

# Build the program
cargo build

# test the program 
cargo test

# Generate a HTML report in the coverage/ directory.
grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing -o ./target/debug/coverage/

View report:

browser open the target/debug/coverage/index.html

Reference:

rust-code-coverage-sample

source_based_code_coverage

grcov