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

`#[no_coverage]` is working but `#[cfg_attr(tarpaulin, no_coverage)]` not #1160

Closed ventaquil closed 1 year ago

ventaquil commented 1 year ago

Describe the bug

I am conditionally add no_coverage attribute only if --cfg tarpaulin is set.

#[cfg_attr(tarpaulin, no_coverage)]
mod info;

It's not working but putting just #[no_coverage] works as expected.

To Reproduce

  1. Create function and add attribute #[cfg_attr(tarpaulin, no_coverage)].
  2. Run cargo tarpaulin.
  3. Check report - function is included in coverage lines.
  4. Change attribute into #[no_coverage].
  5. Run cargo tarpaulin.
  6. Check report - function is ignored as expected.

Expected behavior

Item should be ignored from coverage.

Live example

Check my ferric-bytes/chksum-build repo - specially code below.

https://github.com/ferric-bytes/chksum-build/blob/299e286ddfea98edc0687d63c8959ce7e3ebd264/src/lib.rs#L178-L179

Possible fix

As far as I understand some extra checks should be added to this function.

https://github.com/xd009642/tarpaulin/blob/343e912bf33a3872ff9f49d48686831d7ca701da/src/source_analysis/attributes.rs#L35-L73

xd009642 commented 1 year ago

I've just opened a PR which should fix this, if it does I'll likely do a new release once it's merged in :tada: