Skip to content

Prevent dead-code-elimination before coverage #5

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

Merged
merged 4 commits into from
Jun 10, 2017
Merged

Prevent dead-code-elimination before coverage #5

merged 4 commits into from
Jun 10, 2017

Conversation

phsym
Copy link
Contributor

@phsym phsym commented Jun 6, 2017

By default, there's a dead-code elimination optimization made on rust binary during build process, even for a non --release build.
This dead-code elimination may lead to inaccurate code coverage reports. For example, a function which is not called at all during tests, will be removed from binary, and won't be reported as uncovered. See my example in which I added a untested function, which is not reported as uncovered.

As per rust-lang/rust#31368, passing -C link-dead-code to rustc compiler deactivate dead-code-elimination, improving code coverage accuracy.
When building with cargo, this flag is passed through the environment variable RUSTFLAGS.

Thus, I added RUSTFLAGS="-C link-dead-code" to travis build environment variable and updated README with a note about it.
Now the function is reported as uncovered (see example where the untested function is now reported as uncovered)

@codecov
Copy link

codecov bot commented Jun 6, 2017

Codecov Report

Merging #5 into master will decrease coverage by 7.4%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #5      +/-   ##
==========================================
- Coverage   83.87%   76.47%   -7.41%     
==========================================
  Files           1        1              
  Lines          31       34       +3     
==========================================
  Hits           26       26              
- Misses          5        8       +3
Impacted Files Coverage Δ
src/lib.rs 76.47% <0%> (-7.41%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c49d31f...1bfaed0. Read the comment docs.

@phsym
Copy link
Contributor Author

phsym commented Jun 6, 2017

Coverage decrease is an expected consequence from my modifications

@sunjay
Copy link
Collaborator

sunjay commented Jun 6, 2017

Thanks @phsym! I will look this over and merge it in the next few days.

@sunjay
Copy link
Collaborator

sunjay commented Jun 10, 2017

Thanks for your contribution @phsym! I especially appreciate that you added a section to the README to point out the effect of the added flag and to warn people about accidentally using it in release builds. This is great to have! 😄

@sunjay sunjay merged commit 0f52a3e into codecov:master Jun 10, 2017
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

Successfully merging this pull request may close these issues.

2 participants