Skip to content
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

Files without tests missing from final report #617

Closed
dnaka91 opened this issue May 11, 2021 · 3 comments
Closed

Files without tests missing from final report #617

dnaka91 opened this issue May 11, 2021 · 3 comments

Comments

@dnaka91
Copy link
Contributor

dnaka91 commented May 11, 2021

I noticed that files without any test data are not included in the grcov outputs (specifically the HTML report). This additionally seems to give a wrong coverage percentage, showing a higher percentage than expected as all files without coverage data are not counted in.

Noticed this in my Rust projects so it might be specific to Rust eventually.

Is there any option to tell grcov to take uncovered files into account when generating the report?
Couldn't find anything so far that would help in this regards.

@TilBlechschmidt
Copy link

TilBlechschmidt commented Jun 6, 2021

I ran across the same issue. It is related to the fact that compilers are way too smart these days and strip all the unused functions from the binary. In a test-scenario this means that all the files that have no used functions under a #[cfg(test)] scenario will not be included. This in turn, results in grcov having no clue about them even existing.

For more information, have a look at this Rust PR: rust-lang/rust#31368

TL;DR Run your code with the new compiler flag -Clink-dead-code like this

export RUSTFLAGS="-Zinstrument-coverage -Clink-dead-code"
export LLVM_PROFILE_FILE="coverage-pid%p.profraw"

cargo +nightly test --tests

# Run grcov now as usual

@taiki-e
Copy link

taiki-e commented Jun 10, 2021

This is a bug of -Zinstrument-coverage: rust-lang/rust#86177

Note that -Clink-dead-code works as a workaround, but -Clink-dead-code is basically considered incompatible with -Zinstrument-coverage. So it is likely to cause other problems.
See also richkadel's comments in taiki-e/cargo-llvm-cov#26

@snue
Copy link
Contributor

snue commented Feb 8, 2022

rust-lang/rust#86177 has been resolved.
I think this issue can be closed.

@marco-c marco-c closed this as completed Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants