-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.sh
executable file
·59 lines (47 loc) · 1.77 KB
/
coverage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
set -e
###############################################################################
#
# Dependencies:
#
# $ sudo dnf install lcov
# $ rustup component add llvm-tools-preview
# $ cargo install grcov
# $ cargo install htop
#
###############################################################################
WORKING_DIRECTORY=$(pwd)
CARGO_NAME=$(grep -oE '^name = "[^"]+"' Cargo.toml | grep -oE '"[^"]+"' | grep -oE '[^"]+' | tr '[:lower:]' '[:upper:]')
CARGO_VERSION=$(grep -oE '^version = "[^"]+"' Cargo.toml | grep -oE '"[^"]+"' | grep -oE '[0-9\.]+')
# clean before proceeding
cargo clean
# set instrumenting variables
export CARGO_INCREMENTAL=0
export RUSTDOCFLAGS="-Cpanic=unwind"
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=unwind"
# run all tests
cargo +nightly test --workspace
# prepare output directories for coverage results
mkdir ./target/lcov
mkdir ./target/coverage
# generate coverage info
grcov . --llvm -s . -t lcov --ignore-not-existing \
--excl-line='\s*\}+\)*;?$|\s*/\*\s*$|\s*\} else \{$|\s*\);$|\s*\},$|\s*\)\)+$' \
--ignore "*cargo*" --ignore "*tests*" \
-o ./target/lcov/lcov.info
# generate coverage report in HTML format
genhtml -t "$CARGO_NAME v$CARGO_VERSION" -q -o ./target/coverage ./target/lcov/lcov.info
# generate coverage report in PDF format
if [ "$PDF_REPORT" != "" ]; then
echo ""
echo "Generating PDF report..."
htop -b -l -p A4 --margin=4mm single ./target/coverage/index.html ./target/coverage/coverage.pdf
fi
# display final message
echo ""
echo "Open coverage report:"
echo " HTML file://$WORKING_DIRECTORY/target/coverage/index.html"
if [ "$PDF_REPORT" != "" ]; then
echo " PDF file://$WORKING_DIRECTORY/target/coverage/coverage.pdf"
fi
echo ""