UPDATE3(taiki-e):
If you want to ignore all #[test]-related code, you can use module-level #[coverage(off)] attribute:
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
// ...
}
cargo-llvm-cov excludes code contained in the directory named tests and file named tests.rs/*_tests.rs/*-tests.rs from the report by default, so you can also use it instead of #[coverage(off)] attribute.
#[coverage(off)] attribute has been stabilized in rust-lang/rust#130766 (will be included in Rust 1.85). UPDATE: stabilization has been reverted in rust-lang/rust#134672.
UPDATE2(taiki-e):
See #123 (comment)
UPDATE(taiki-e):
If you want to ignore all #[test]-related code, consider using coverage-helper crate version 0.2+.
cargo-llvm-cov excludes code contained in the directory named tests from the report by default, so you can also use it instead of coverage-helper crate.
https://github.com/taiki-e/cargo-llvm-cov#exclude-function-from-coverage
AFAIK this is not currently possible (though I would love to be proven wrong), so just filing this as a nice-to-have tracking issue.
What I would like is that only library code counts towards coverage. Having all of the #[test] and #[cfg(test)] code (fn and whole utility modules) count towards coverage metrics right now skews those numbers up quite a bit.
Right now cargo-llvm-cov automatically ignores all the examples and tests code via -ignore-filename-regex but unit test functions are still counted (and possibly doctests once those are being fixed [tentative fix in #122]).
UPDATE3(taiki-e):
UPDATE: stabilization has been reverted in rust-lang/rust#134672.#[coverage(off)]attribute has been stabilized in rust-lang/rust#130766 (will be included in Rust 1.85).UPDATE2(taiki-e):
See #123 (comment)
UPDATE(taiki-e):
https://github.com/taiki-e/cargo-llvm-cov#exclude-function-from-coverage
AFAIK this is not currently possible (though I would love to be proven wrong), so just filing this as a nice-to-have tracking issue.
What I would like is that only library code counts towards coverage. Having all of the
#[test]and#[cfg(test)]code (fn and whole utility modules) count towards coverage metrics right now skews those numbers up quite a bit.Right now
cargo-llvm-covautomatically ignores all theexamplesandtestscode via-ignore-filename-regexbut unit test functions are still counted (and possibly doctests once those are being fixed [tentative fix in #122]).