Skip to content

Commit ccbd059

Browse files
committed
Add test coverage
1 parent cec211f commit ccbd059

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

.ci/test-cover

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
DESTDIR="${PWD}/target/cover"
6+
7+
rustup component add llvm-tools
8+
cargo install grcov
9+
10+
export RUSTFLAGS="-Cinstrument-coverage"
11+
if [ "$(uname -o)" = "Darwin" ]; then
12+
export RUSTFLAGS="-Clink-arg=-Wl,-undefined,dynamic_lookup $RUSTFLAGS"
13+
fi
14+
15+
export LLVM_PROFILE_FILE="${DESTDIR}/default_%m_%p.profraw"
16+
cargo test
17+
18+
grcov "${DESTDIR}" \
19+
--ignore '**/clang-sys*/**' \
20+
--ignore "$HOME/.cargo/**" \
21+
--ignore-not-existing \
22+
--excl-start 'begin_impossible!' \
23+
--excl-stop 'end_impossible!' \
24+
--llvm \
25+
--binary-path "target/debug/" \
26+
-s . \
27+
--branch \
28+
-o "${DESTDIR}" \
29+
--output-types html,cobertura
30+
31+
xmllint --xpath "concat('Coverage: ', 100 * string(//coverage/@line-rate), '%')" "${DESTDIR}/cobertura.xml"
32+
33+
if [ "$(uname -o)" = "Darwin" ] && [ -z "$CI" ]; then
34+
open "${DESTDIR}/html/index.html"
35+
fi

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ test:
99
.PHONY: lint # Lint the project
1010
lint: .pre-commit-config.yaml
1111
@pre-commit run --show-diff-on-failure --color=always --all-files
12+
13+
.PHONY: cover # Run cover tests and generate & open a report.
14+
cover:
15+
@./.ci/test-cover

0 commit comments

Comments
 (0)