xd009642 / tarpaulin

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

#[cfg(not(tarpaulin_include))] does not work on trait implementations #947

Closed elinorbgr closed 2 years ago

elinorbgr commented 2 years ago

Consider this code extracted from one of my projects:

#[cfg(not(tarpaulin_include))]
impl<E> Debug for InsertError<E> {
    fn fmt(&self, formatter: &mut Formatter) -> Result<(), fmt::Error> {
        write!(formatter, "{:?}", self.error)
    }
}

In the coverage report, the fmt method is marked as uncovered, which is not expected given the #[cfg(not(tarpaulin_include))] annotation.

xd009642 commented 2 years ago

So I tried this in an example project and added the example snippet you added to the source_analysis tests to see if it failed but it showed all the lines as marked to ignore. Do you have a public project I can check against?

elinorbgr commented 2 years ago

Sure, this is triggered on my calloop project, for example all those implementations are reported as uncovered on the codecov report :

https://github.com/Smithay/calloop/blob/7198d715d056b05b490e4c907b609a3da8f650ae/src/loop_logic.rs#L71-L97

xd009642 commented 2 years ago

Well just ran tarpaulin on it with --ignore-tests --all-features like in your CI and they weren't marked as covered. Potentially this is something already fixed but I forgot doing or maybe you're on an outdated tarpaulin version?

Below image is a screenshot from the Html report showing the lines marked as uncoverable

Screenshot from 2022-01-28 14-37-04

elinorbgr commented 2 years ago

Ah, indeed, that report was generated using tarpaulin 0.18.5, I suppose this has been fixed since then. Sorry for the noise!