Skip to content

Commit

Permalink
chore: add coverage gathering script (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller committed Apr 27, 2023
1 parent 0534edf commit 5fc7903
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions tasks/coverage.sh
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!'
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ fn test_parse_simple_json_template() {
mappings: MappingsParseTree::new(),
conditions: ConditionsParseTree::new(),
logical_lookup: CloudformationParseTree::build_logical_lookup(&resources),
resources: resources,
resources,
outputs: OutputsParseTree::new(),
};

Expand Down

0 comments on commit 5fc7903

Please sign in to comment.