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

Ignore a specific line for coverage #1382

Closed nth10sd closed 1 year ago

nth10sd commented 1 year ago

# pragma: no cover allows coverage.py users to specify a particular line to ignore in code coverage.

May I know if there's a equivalent in tarpaulin? My use case is in maturin repositories, which use #[pyfunction] macros. Tarpaulin marks these #[pyfunction] macro lines as being not covered and I'd like to ignore them in tarpaulin reports.

The current way of ignoring via #[cfg(not(tarpaulin_include))] only allows ignoring whole functions, not specific macro lines.

xd009642 commented 1 year ago

Macro attributes are already meant to be ignored, so there's something wrong in the source analysis module there. If you have a repo I can look at I'll see if I can spot it out

nth10sd commented 1 year ago
use pyo3::prelude::{pyfunction, PyResult};

#[pyfunction]
pub fn print_something() -> PyResult<()> {
    println!("foo");
    Ok(())
}

#[cfg(test)]
mod mod_test_print_something {
    use super::print_something;

    #[test]
    fn test_print_something() {
        print_something().ok().unwrap()
    }
}

Here's an extract. The only line that tarpaulin claims to not cover is the #[pyfunction] one.

xd009642 commented 1 year ago

https://github.com/xd009642/tarpaulin/pull/1384 draft PR started, I'll add it on impl blocks, methods and traits as well

xd009642 commented 1 year ago

Okay done and released, you can reopen this if you still think there's a need for the pragma comments, but the macros should apply to everything in rust that isn't a macro/attribute so I have a feeling there's no need provided tarpaulin ignores attributes etc correctly

nth10sd commented 1 year ago

Okay done and released

@xd009642 I've retested with version 0.27.0, yes, you've fixed this issue as the pyfunction macro is now covered!

Please feel free to rename this issue to something more appropriate.