Files
regorus/scripts/coverage
Anand Krishnamoorthi e93b33ea05 Support build on non Linux platforms
cargo config
1. MUSL is no longer the default target. This allows building on Mac and Windows.
2. On Linux, code coverage compiler options are supplied by default.

pre-commit, pre-push
- Coverage is turned on only on Linux
- clippy is run on all platforms

github
- MUSL build is tested to ensure that stand alone executables can be created

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-01 15:45:44 +05:30

72 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
set -e
if ! command -v grcov > /dev/null; then
cargo install grcov
fi
if ! command -v llvm-profdata > /dev/null; then
rustup component add llvm-tools-preview
fi
#export LLVM_PROFILE_FILE='target/cargo-test-%p-%m.profraw'
#export CARGO_INCREMENTAL=1
#export RUSTFLAGS='-Cinstrument-coverage'
echo "Building with instrumentation"
cargo build --all-targets
if [ "$1" == "--no-run" ]; then
exit 0
fi
# Remove existing coverage information.
rm -f target/*.profraw
rm -rf target/coverage
mkdir -p target/coverage
echo "Running tests"
cargo test
# Generate html
grcov target/ --binary-path ./target/debug/deps -s src/ -t html \
--branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/html
if [ "$1" == "--show" ]; then
echo "Opening report in browser"
xdg-open target/coverage/html/index.html 2>/dev/null
echo "Done"
fi
# Generate markdown
grcov target/ --binary-path ./target/debug/deps -s src/ -t markdown \
--branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/markdown
cat target/coverage/markdown
# Print small-form table of files without 100% coverage.
echo "Files without 100% coverage"
while read p; do
file=$(echo "$p" | cut -f 2 -d '|')
percent=$(echo "$p" | cut -f 3 -d '|')
missing=$(echo "$p" | cut -f 5 -d '|')
if [ -z "$file" ]; then
break
fi
# Trim percentage using xargs.
case $(echo "$percent" | xargs) in
"100%")
continue
esac
echo "| $file | $percent |"
done < target/coverage/markdown
#TODO: Maybe use coveralls format (json) and query data to lockdown code coverage.