diff --git a/.travis.yml b/.travis.yml index 58c445b..168cc02 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,10 @@ matrix: allow_failures: - rust: nightly +env: + global: + - RUSTFLAGS="-C link-dead-code" + before_install: - sudo apt-get update diff --git a/README.md b/README.md index 056003b..831acf0 100644 --- a/README.md +++ b/README.md @@ -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. @@ -71,6 +76,10 @@ matrix: allow_failures: - rust: nightly +env: + global: + - RUSTFLAGS="-C link-dead-code" + before_install: - sudo apt-get update diff --git a/src/lib.rs b/src/lib.rs index 81a0669..327d858 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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::*;