-
Notifications
You must be signed in to change notification settings - Fork 12.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Oddity in what lines count towards coverage #68703
Comments
Coverage is based on debug info. If there's a bug in debuginfo generation, please provide a more concrete example (like the code needed to reproduce the issue, and an explanation about why the emitted debuginfo is wrong). |
They are compiled, so they get debuginfo.
Could you give an example where it is and isn't counted?
If you derive a trait for a struct/enum then the impls will have the struct/enum definition as span.
Vtable shims?
Likely dropping of locals.
I don't know why that is. |
I was wondering myself. To give a specific example from How to Write Tests: pub fn greeting(name: &str) -> String {
format!("Hello {}!", name)
}
pub fn add_two(a: i32) -> i32 {
a + 2
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn greeting_contains_name() {
let result = greeting("Carol");
assert!(result.contains("Carol"));
}
#[test]
fn it_adds_two() {
assert_eq!(4, add_two(2));
}
} Executing cargo clean
CARGO_INCREMENTAL=0 RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Copt-level=0 -Zpanic_abort_tests -Cpanic=abort" cargo b
CARGO_INCREMENTAL=0 RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Copt-level=0 -Zpanic_abort_tests -Cpanic=abort" cargo t
grcov target/debug/ --ignore "/*" -s . --llvm --branch --ignore-not-existing -o html -t html Gives a 76.9% line coverage and 62.5% function coverage... |
I'm curious if folks here have used the instrumentation-based code coverage feature? As @jonas-schievink points out, While it's possible we could make tweaks there, we already have a specific code coverage feature so I would encourage folks to use that instead of debuginfo-based code coverage tools. If there are tooling gaps with instrumentation-based code coverage, we should try to close them. |
@wesleywiser grcov supports both options. Source-based coverage is the suggested one in grcov's docs: https://github.com/mozilla/grcov#example-how-to-generate-source-based-coverage-for-a-rust-project. |
I asked this over on
mozilla/grcov
but then realized that it is better suited to here.While using the following
RUSTFLAGS
to generate coverage reports I have found some odditites with what is considers to be covered/not-covered/not-needed to be covered.mod tests
) are counted towards coverageWould it be possible to either add a flag to ignore these, or to just ignore them all the time?
The text was updated successfully, but these errors were encountered: