From 7c7f331b535fa4a03fe748464f9f0600d1df95b6 Mon Sep 17 00:00:00 2001 From: Vincent Thiberville Date: Sun, 22 May 2022 11:37:17 +0200 Subject: [PATCH] feat: add script to generate coverage --- .gitignore | 1 + scripts/cov.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 scripts/cov.sh diff --git a/.gitignore b/.gitignore index ea8c4bf7..6d33677d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/coverage /target diff --git a/scripts/cov.sh b/scripts/cov.sh new file mode 100755 index 00000000..69961d77 --- /dev/null +++ b/scripts/cov.sh @@ -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