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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ matrix:
allow_failures:
- rust: nightly

env:
global:
- RUSTFLAGS="-C link-dead-code"

before_install:
- sudo apt-get update

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ for each test executable and store the results in separate directories.**
Codecov will automatically find and upload the cobertura.xml files and
merge the coverage for you.

Note that setting the environment variable `RUSTFLAGS="-C link-dead-code"`
during tests build may improve coverage accuracy by preventing dead-code elimination.
Do not set this variable when creating release builds since it will increase
binary size.

After you've run the tests and created a cobertura.xml report, you can
use [the Codecov global uploader][4] to push that report to Codecov.
See below for further details.
Expand Down Expand Up @@ -71,6 +76,10 @@ matrix:
allow_failures:
- rust: nightly

env:
global:
- RUSTFLAGS="-C link-dead-code"

before_install:
- sudo apt-get update

Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ pub fn which(face: &str) -> &'static str {
}
}

/// This function is not called during tests, so it will be considered dead code.
/// By default, and because of dead-code elimination it won't be reported as uncovered
/// since the function will be removed from executable.
/// This is accounted for in the Travis configuration by passing the compiler flag
/// `-C link-dead-code` when building the tests. This flag disables dead code
/// elimination and allows this function to be reported correctly.
pub fn not_called() {
println!("This is dead code");
unreachable!();
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down