Skip to content

Commit

Permalink
switch coverage from tarpaulin to llvm-cov
Browse files Browse the repository at this point in the history
  • Loading branch information
nicbus committed Feb 23, 2024
1 parent 1d2d77b commit b9a09a7
Showing 1 changed file with 59 additions and 27 deletions.
86 changes: 59 additions & 27 deletions tests/coverage.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,61 @@
#!/bin/bash -e
#
# 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

# install tarpaulin if missing
cargo tarpaulin --help >/dev/null 2>&1 || cargo install cargo-tarpaulin

# 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

# open the html test report in the default browser
xdg-open tarpaulin-report.html
# script to run project tests and report code coverage
# uses llvm-cov (https://github.com/taiki-e/cargo-llvm-cov)

LLVM_COV_OPTS=""
CARGO_TEST_OPTS=""

_die() {
echo "err $*"
exit 1
}

_tit() {
echo
echo "========================================"
echo "$@"
echo "========================================"
}

help() {
echo "$NAME [-h|--help] [-t|--test] [--no-clean]"
echo ""
echo "options:"
echo " -h --help show this help message"
echo " -t --test only run these test(s)"
echo " --no-clean don't cleanup before the run"
}

# cmdline arguments
while [ -n "$1" ]; do
case $1 in
-h|--help)
help
exit 0
;;
-t|--test)
CARGO_TEST_OPTS="-- $2"
shift
;;
--no-clean)
LLVM_COV_OPTS="$1"
;;
*)
help
_die "unsupported argument \"$1\""
;;
esac
shift
done

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

_tit "generating coverage report"
# shellcheck disable=2086
cargo llvm-cov --html $LLVM_COV_OPTS $CARGO_TEST_OPTS

## show html report location
echo "generated html report: target/llvm-cov/html/index.html"

0 comments on commit b9a09a7

Please sign in to comment.