Skip to content

Commit

Permalink
feat: add script to generate coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vthib committed May 22, 2022
1 parent 36d6206 commit 7c7f331
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/coverage
/target
35 changes: 35 additions & 0 deletions scripts/cov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Build HTML coverage report. Requires Rust 1.60+ with llvm-tools-preview component
# Run this script from the root directory of the repo.

set -eux

ROOT_PATH=$(dirname "$(readlink -f "$0")")/..

cd $ROOT_PATH
rm -rf ./coverage

export LLVM_PROFILE_FILE="$ROOT_PATH/coverage/profiles/%p.profraw"

# Run all tests with coverage
RUSTFLAGS="-C instrument-coverage" cargo test --all-features

# Merge different profraw files
$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata \
merge -sparse ./coverage/profiles/*.profraw -o coverage/profiles/merge.profdata

# Build list of executables, should be the list of test binaries :/
BINS=$(find target/debug/deps -type f -executable | grep -v '.so$')

# Generate HTML report in coverage directory
$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov \
show --Xdemangler=rustfilt \
$(echo $BINS | xargs -d' ' -I{} echo --object '{}') \
--instr-profile=./coverage/profiles/merge.profdata \
--show-line-counts-or-regions \
--show-instantiations \
--ignore-filename-regex='/.cargo/(registry|git)' \
--use-color \
--output-dir coverage \
--format html

0 comments on commit 7c7f331

Please sign in to comment.