Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add coverage gathering script #113

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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