Skip to content

Instantly share code, notes, and snippets.

@hn3000
Created April 23, 2021 22:50
Show Gist options
  • Save hn3000/80b4b2e72ac15272f0db0cf09f29fc52 to your computer and use it in GitHub Desktop.
Save hn3000/80b4b2e72ac15272f0db0cf09f29fc52 to your computer and use it in GitHub Desktop.
rust test coverage with grcov
METHOD=${1:-${METHOD:-"A"}}
if [ "$METHOD" == "A" ]
then
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
export RUSTDOCFLAGS="-Cpanic=abort"
unset LLVM_PROFILE_FILE
else
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
export RUSTDOCFLAGS="-Cpanic=abort"
export LLVM_PROFILE_FILE="your_name-%p-%m.profraw"
fi
cargo clean
cargo build
cargo test
grcov . -s . --binary-path ./target/debug/ -t html --excl-br-line 'assert' --excl-start '#(\[cfg\(test\)\]|\[test\])' --branch --ignore-not-existing --ignore test/ -o ./grcov-coverage/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment