-
Notifications
You must be signed in to change notification settings - Fork 3
/
coverage.sh
42 lines (34 loc) · 1.53 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
#!/bin/sh
# grcov and lcov must be installed for this to run:
#
# $ cargo install grcov
# $ sudo apt install lcov # or what the equivalent on your platform is
# set flags for coverage
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"
# build and run tests using these two commands in every component directory
cargo build
cargo test -- --test-threads=1
cargo test -- --ignored
# use grcov to generate report info
mkdir -p ./target/coverage
grcov -s . --llvm --branch --ignore-not-existing \
--excl-br-start "mod tests \{" \
--excl-start "mod tests \{" \
--excl-br-line "#\[derive\(|^/{2,3}|impl" \
--excl-line "#\[derive\(|^/{2,3}|impl" \
-o ./target/coverage/full.info \
./target/debug
# filter the report using lcov
lcov --extract ./target/coverage/full.info \
$(find src -type f -regextype posix-extended -regex '.*\b\w+?\.rs$') \
-o ./target/coverage/extracted.info
lcov --remove ./target/coverage/extracted.info \
$(find src -type f -regextype posix-extended -regex '.*\b(lib|bindings)\.rs$') \
-o ./target/coverage/xdrk.info
# generate report for GitLab CI
lcov --list ./target/coverage/xdrk.info
# finally, generate HTML
genhtml --show-details --highlight --ignore-errors source --legend \
-o ./target/coverage/html ./target/coverage/xdrk.info