Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 25, 2024
1 parent cec211f commit ccbd059
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .ci/test-cover
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e

DESTDIR="${PWD}/target/cover"

rustup component add llvm-tools
cargo install grcov

export RUSTFLAGS="-Cinstrument-coverage"
if [ "$(uname -o)" = "Darwin" ]; then
export RUSTFLAGS="-Clink-arg=-Wl,-undefined,dynamic_lookup $RUSTFLAGS"
fi

export LLVM_PROFILE_FILE="${DESTDIR}/default_%m_%p.profraw"
cargo test

grcov "${DESTDIR}" \
--ignore '**/clang-sys*/**' \
--ignore "$HOME/.cargo/**" \
--ignore-not-existing \
--excl-start 'begin_impossible!' \
--excl-stop 'end_impossible!' \
--llvm \
--binary-path "target/debug/" \
-s . \
--branch \
-o "${DESTDIR}" \
--output-types html,cobertura

xmllint --xpath "concat('Coverage: ', 100 * string(//coverage/@line-rate), '%')" "${DESTDIR}/cobertura.xml"

if [ "$(uname -o)" = "Darwin" ] && [ -z "$CI" ]; then
open "${DESTDIR}/html/index.html"
fi
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ test:
.PHONY: lint # Lint the project
lint: .pre-commit-config.yaml
@pre-commit run --show-diff-on-failure --color=always --all-files

.PHONY: cover # Run cover tests and generate & open a report.
cover:
@./.ci/test-cover

0 comments on commit ccbd059

Please sign in to comment.