From 66594038f68a80984a163483bd2369eaa34780b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=A7=91=F0=9F=8F=BB=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier?= Date: Thu, 27 Apr 2023 17:22:16 +0200 Subject: [PATCH] chore: add coverage gathering script --- tasks/coverage.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ tests/tests.rs | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 tasks/coverage.sh diff --git a/tasks/coverage.sh b/tasks/coverage.sh new file mode 100755 index 00000000..35fa223f --- /dev/null +++ b/tasks/coverage.sh @@ -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!' diff --git a/tests/tests.rs b/tests/tests.rs index cf61d6ea..2159bb81 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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(), };