From c1961f11f2cb7aa2d259cc02684d068108192a5b Mon Sep 17 00:00:00 2001 From: Pierre-Henri Symoneaux Date: Tue, 6 Jun 2017 10:50:40 +0200 Subject: [PATCH 1/4] Added an uncovered function. --- src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 81a0669..21e6faf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,14 @@ pub fn which(face: &str) -> &'static str { } } +/// This function is not called in tests. It will be considered as dead code. +/// Because of dead-code elimination it won't be reported as uncovered +/// since the function will be removed from executable +pub fn not_called() { + println!("This is dead code"); + unreachable!(); +} + #[cfg(test)] mod tests { use super::*; From 7658dfdf52ca78311dc09ee3dcabf7e9413833a4 Mon Sep 17 00:00:00 2001 From: Pierre-Henri Symoneaux Date: Tue, 6 Jun 2017 11:01:26 +0200 Subject: [PATCH 2/4] Added RUSTFLAGS="-C link-dead-code" env variable to travis script --- .travis.yml | 4 ++++ src/lib.rs | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) 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/src/lib.rs b/src/lib.rs index 21e6faf..2c5a83e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,9 +35,11 @@ pub fn which(face: &str) -> &'static str { } } -/// This function is not called in tests. It will be considered as dead code. -/// Because of dead-code elimination it won't be reported as uncovered -/// since the function will be removed from executable +/// This function is not called during tests thus it will be considered as 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. Hopefully you can pass +/// the rustflag `-C link-dead-code` when building the tests in order to +/// prevent dead-code elimination pub fn not_called() { println!("This is dead code"); unreachable!(); From af39054ed5e9641dfe0f4a0242dd514ea4e9284e Mon Sep 17 00:00:00 2001 From: Pierre-Henri Symoneaux Date: Tue, 6 Jun 2017 11:09:07 +0200 Subject: [PATCH 3/4] Updated readme with a note on dead-code elimination --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 056003b..0189524 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. +This variable should not be set when building releases 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 From 1bfaed03c0f5d456807ab000effc23b470a7a7ec Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Fri, 9 Jun 2017 20:30:06 -0400 Subject: [PATCH 4/4] Changed the wording in the sections added to the README and example --- README.md | 2 +- src/lib.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0189524..831acf0 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ 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. -This variable should not be set when building releases since it will increase +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 diff --git a/src/lib.rs b/src/lib.rs index 2c5a83e..327d858 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,11 +35,12 @@ pub fn which(face: &str) -> &'static str { } } -/// This function is not called during tests thus it will be considered as dead code. +/// 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. Hopefully you can pass -/// the rustflag `-C link-dead-code` when building the tests in order to -/// prevent dead-code elimination +/// 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!();