Skip to content

Commit 9992238

Browse files
authored
enforce 100% test coverage (#23)
* now update CI * debug * fix bug * revert * now fail CI on <100% coverage * remove one line of dead code * revert now * shorten --------- Co-authored-by: Luke Videckis <lukevideckis@gmail.com>
1 parent 255cee9 commit 9992238

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on: [push, workflow_dispatch]
44

55
env:
66
CARGO_TERM_COLOR: always
7-
# causes CI to fail on any warning
8-
RUSTFLAGS: -D warnings
7+
# `-D warnings` causes CI to fail on any warning
8+
RUSTFLAGS: -D warnings -C instrument-coverage -C link-dead-code
99
RUSTDOCFLAGS: -D warnings
1010

1111
jobs:
@@ -36,6 +36,8 @@ jobs:
3636
rustup install nightly
3737
rustup override set nightly
3838
rustup component add --toolchain nightly rustfmt clippy
39+
cargo install cargo-binutils
40+
rustup component add llvm-tools-preview
3941
- name: install oj-verify submodule
4042
run: |
4143
git submodule init
@@ -46,8 +48,6 @@ jobs:
4648
# clear submodule afterwards to not run tests in verification-helper
4749
git submodule deinit --all -f
4850
- name: run tests
49-
# regarging `--tle 2`: the oj-verify tool only allows testing in release mode
50-
#
5151
# regarding `--jobs 4`: github CI runs with 4 cores
5252
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
5353
#
@@ -61,3 +61,9 @@ jobs:
6161
# since all tests are rerun on every commit anyways, there's no need for
6262
# the .verify-helper/timestamps.remote.json file
6363
run: oj-verify all --tle 10 --jobs 4 --timeout 21600
64+
# https://doc.rust-lang.org/rustc/instrument-coverage.html
65+
- name: code coverage
66+
run: |
67+
cargo profdata -- merge -sparse default_*.profraw -o json5format.profdata
68+
cargo cov -- report --use-color --ignore-filename-regex='/.cargo/registry' --instr-profile=json5format.profdata $(find target/debug/examples -type f -executable)
69+
cargo cov -- export --ignore-filename-regex='/.cargo/registry' --instr-profile=json5format.profdata $(find target/debug/examples -type f -executable) | python -c "import sys, json; l=json.load(sys.stdin)['data'][0]['totals']['lines']; assert(l['count'] == l['covered'])"

0 commit comments

Comments
 (0)