xd009642 / tarpaulin

A code coverage tool for Rust projects
https://crates.io/crates/cargo-tarpaulin
Apache License 2.0
2.5k stars 180 forks source link

Run tests multiple times and get full code coverage #1328

Closed 0xMimir closed 1 year ago

0xMimir commented 1 year ago

In most project you have many tests, but order of those tests, where and when they are run is different, so in most cases we have unit tests, and rest of tests have #[ignore] and we use test script to run them with correct params, and in correct order, this is example test script

cargo test -- --ignored test_project_seeding
cargo test -- --ignored test_data_seeding
cargo test

Tests test_project_seeding and test_data_seeding have #[ignored] so they are not ran by default, test_project_seeding is used to test if project correctly setups everything needed to run project, test_data_seeding is used to test adding data to DB and seed data that is used for cargo test, if cargo test is replaced with cargo tarpaulin I get 3 different outputs, with unrelated coverage results. when generating report with grcov I get full code coverage from all three runs these are commands I use:

CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' cargo build

CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test -- --ignored test_project_seeding
CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test -- --ignored test_data_seeding
CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test

grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o ./coverage/html

Is there a way to generate full code coverage like with grcov using tarpaulin, If there is not I would suggest that as a feature

xd009642 commented 1 year ago

You can do it by using the config files to specify multiple tarpaulins run to do and merge together

0xMimir commented 1 year ago

Thanks for reply, I found the solution, for anyone having the same issue create tarpaulin.toml and for example above .toml would contain:

[subtract_test]
args = ["--ignored", "test_project_seeding"]

[divide_test]
args = ["--ignored", "test_data_seeding"]

[test]

Cargo tarpaulin will automatically merge results of every run.