diff --git a/.gitignore b/.gitignore index 1805f5f71..bb9d304d0 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ deltachat-ffi/html deltachat-ffi/xml .rsynclist + +coverage/ diff --git a/ci_scripts/coverage.sh b/ci_scripts/coverage.sh new file mode 100755 index 000000000..6bd7c92dd --- /dev/null +++ b/ci_scripts/coverage.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -eu + +if ! which grcov 2>/dev/null 1>&2; then + echo >&2 '`grcov` not found. Check README at https://github.com/mozilla/grcov for setup instructions.' + echo >&2 'Run `cargo install grcov` to build `grcov` from source.' + exit 1 +fi + +# Allow `-Z` flags without using nightly Rust. +export RUSTC_BOOTSTRAP=1 + +# We are using `-Zprofile` instead of source-based coverage [1] +# (`-Zinstrument-coverage`) due to a bug resulting in empty reports [2]. +# +# [1] https://blog.rust-lang.org/inside-rust/2020/11/12/source-based-code-coverage.html +# [2] https://github.com/mozilla/grcov/issues/595 + +export CARGO_INCREMENTAL=0 +export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" +export RUSTDOCFLAGS="-Cpanic=abort" +cargo clean +cargo build +cargo test + +grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./coverage/