-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add coverage gathering script (#113)
- Loading branch information
1 parent
0534edf
commit 5fc7903
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
COVERAGE_ROOT="${PWD}/target/coverage" | ||
|
||
rm -rf ${COVERAGE_ROOT} | ||
mkdir -p ${COVERAGE_ROOT}/profraw | ||
|
||
echo 'Running tests with coverage instrumentation...' | ||
|
||
CARGO_INCREMENTAL=0 \ | ||
RUSTFLAGS='-Cinstrument-coverage' \ | ||
LLVM_PROFILE_FILE="${COVERAGE_ROOT}/profraw/%p-%m.profraw" \ | ||
cargo test | ||
|
||
if ! command -v grcov &>/dev/null; then | ||
echo 'Installing grcov...' | ||
cargo install grcov | ||
fi | ||
|
||
if ! rustup component list --installed | grep -e '^llvm-tools'; then | ||
echo 'Installing the llvm-tools-preview rustup component...' | ||
rustup component add llvm-tools-preview | ||
fi | ||
|
||
echo 'Generating coverage reports...' | ||
grcov "${COVERAGE_ROOT}/profraw" \ | ||
--binary-path "${PWD}/target/debug/deps" \ | ||
--source-dir "${PWD}" \ | ||
--output-types "html,lcov" \ | ||
--branch \ | ||
--ignore-not-existing \ | ||
--keep-only "src/*" \ | ||
--ignore "src/main.rs" \ | ||
--output-path "${COVERAGE_ROOT}" \ | ||
--commit-sha $(git rev-parse HEAD) \ | ||
--service-name "noctilucent" | ||
|
||
# Rename `lcov` to a name that is aligned with what IDEs usually look for... | ||
mv "${COVERAGE_ROOT}/lcov" "${COVERAGE_ROOT}/lcov.info" | ||
|
||
echo 'Cleaning up...' | ||
rm -rf "${COVERAGE_ROOT}/profraw" | ||
|
||
echo 'All done!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters