2021-11-22 17:54:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-11-23 14:03:20 +00:00
|
|
|
# usage: with_coverage <command> [args...] : run <command> with [args...]
|
|
|
|
# with_coverage : runs bash interactively
|
|
|
|
|
2021-11-22 17:54:21 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
COVERAGE_BASEDIR=$(git rev-parse --show-toplevel)
|
|
|
|
export RUSTFLAGS="-Z instrument-coverage"
|
|
|
|
export LLVM_PROFILE_FILE=$COVERAGE_BASEDIR/coverage_meta/%p-%m.profraw
|
|
|
|
export RUSTUP_TOOLCHAIN=nightly
|
|
|
|
|
|
|
|
rm -r "$COVERAGE_BASEDIR/coverage" || true
|
2021-11-23 21:03:02 +00:00
|
|
|
rm -r "$COVERAGE_BASEDIR/coverage_meta" || true
|
|
|
|
|
2021-11-22 17:54:21 +00:00
|
|
|
mkdir -p "$COVERAGE_BASEDIR/coverage"
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
# when run interactivelly, don't die on error
|
|
|
|
bash || true
|
|
|
|
else
|
|
|
|
"$@"
|
|
|
|
fi
|
|
|
|
|
2021-11-23 21:03:02 +00:00
|
|
|
echo "Generating report..."
|
|
|
|
|
2021-11-22 17:54:21 +00:00
|
|
|
grcov "$COVERAGE_BASEDIR/coverage_meta" --binary-path "$COVERAGE_BASEDIR/target/debug/" \
|
|
|
|
-s "$COVERAGE_BASEDIR/crates/" -o "$COVERAGE_BASEDIR/coverage" -t html --branch \
|
|
|
|
--ignore-not-existing --excl-start '^mod test' --excl-stop '^}' \
|
|
|
|
--ignore="*/tests/*" --ignore="*/examples/*"
|
|
|
|
|
2021-11-23 21:03:02 +00:00
|
|
|
# Extract coverage information and print it to the command line.
|
2021-11-22 17:54:21 +00:00
|
|
|
awk '{if (match($0, /<p class="heading">([^<]*)<\/p>/, groups)) {
|
|
|
|
last_match=groups[1]
|
|
|
|
} else if (match($0, /<abbr title="[0-9]* \/ [0-9]*">([^<]*)<\/abbr>/, groups)) {
|
|
|
|
print last_match " " groups[1]
|
|
|
|
}}' "$COVERAGE_BASEDIR/coverage/index.html"
|
2021-11-23 21:03:02 +00:00
|
|
|
|
2021-11-22 17:54:21 +00:00
|
|
|
echo "Full report: $COVERAGE_BASEDIR/coverage/index.html"
|