Skip to content

Commit

Permalink
switch coverage from tarpaulin to grcov
Browse files Browse the repository at this point in the history
  • Loading branch information
nicbus committed Feb 22, 2024
1 parent e6b568f commit d63382c
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions tests/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,39 @@
#
# script to run projects tests and report code coverage
#
# uses tarpaulin (https://crates.io/crates/cargo-tarpaulin)
#
# other coverage solutions exist but all require rust nightly and the project
# does not build with nightly at the moment
# uses grcov (https://github.com/mozilla/grcov)

COVERAGE_DIR="target/coverage"

# install tarpaulin if missing
cargo tarpaulin --help >/dev/null 2>&1 || cargo install cargo-tarpaulin
_tit() {
echo
echo "========================================"
echo "$@"
echo "========================================"
}

_tit "installing requirements"
rustup component add llvm-tools-preview
cargo install grcov

_tit "gathering coverage info"
# enable code coverage instrumentation and set per-test profile file name
export RUSTFLAGS="-Cinstrument-coverage"
export RUSTDOCFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE="$COVERAGE_DIR/%p-%m.profraw"
# run tests
# --skip-clean to avoid re-building everything each time
cargo tarpaulin \
--count \
--line \
--locked \
--skip-clean \
--ignore-tests \
--exclude-files rgb-lib-ffi/ \
--exclude-files tests/ \
--exclude-files src/wallet/test/ \
--out Html \
-- \
--test-threads=1
rm -rf $COVERAGE_DIR && mkdir -p $COVERAGE_DIR
cargo test --no-fail-fast || true

_tit "generating coverage report"
grcov $COVERAGE_DIR \
-s . \
--binary-path target/debug/ \
--output-types html \
--branch \
--ignore 'target/*' \
--ignore-not-existing \
-o $COVERAGE_DIR/

# open the html test report in the default browser
xdg-open tarpaulin-report.html
## show html report location
echo "generated html report: $COVERAGE_DIR/html/index.html"

0 comments on commit d63382c

Please sign in to comment.