Repository: xd009642/tarpaulin
Pull request #1107 (2022-10-07 08:33:08)

on pull request target
<!--- When contributing to tarpaulin all contributions should branch off the -->
<!--- develop branch as master is only used for releases. --> 

<!--- Check CONTRIBUTING.md for more information-->

<!--- Please describe the changes in the PR and them motivation below -->



Patch:
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 075d769..c524cfc 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -3,8 +3,8 @@ on:
   push:
     branches:
       - "*"
+  pull_request_target:
   pull_request:
-
 env:
   RUST_BACKTRACE: 1
 
@@ -37,6 +37,14 @@ jobs:
       - name: ignored test
         run: cargo test -- --ignored || true
         if: matrix.version == 'nightly'
+      - uses: actions/upload-artifact@v3
+        if: failure()
+        with:
+          name: linux ${{ matrix.version }}
+          retention-days: 3
+          path: |
+              tests/data/
+              !tests/data/**/*.rs
       - name: check formatting
         run: cargo fmt -- --check
   windows:
@@ -44,6 +52,7 @@ jobs:
     strategy:
       matrix:
         version:
+          - stable
           - nightly
         target:
           - x86_64-pc-windows-gnu
@@ -61,11 +70,20 @@ jobs:
         run: cargo build
       - name: test
         run: cargo test
+      - uses: actions/upload-artifact@v3
+        if: failure()
+        with:
+          name: windows ${{ matrix.version }}
+          retention-days: 3
+          path: |
+              tests/data/
+              !tests/data/**/*.rs
   mac:
     runs-on: macos-latest
     strategy:
       matrix:
         version:
+          - stable
           - nightly
         target:
           - x86_64-apple-darwin	
@@ -82,6 +100,14 @@ jobs:
         run: cargo build
       - name: test
         run: cargo test
+      - uses: actions/upload-artifact@v3
+        if: failure()
+        with:
+          name: mac ${{ matrix.version }}
+          retention-days: 3
+          path: |
+              tests/data/
+              !tests/data/**/*.rs
   coverage:
     runs-on: ubuntu-latest
     strategy:
@@ -98,4 +124,4 @@ jobs:
           toolchain: ${{ matrix.version }}
           override: true
       - name: coverage
-        run: cargo run --release -- tarpaulin --engine llvm --follow-exec --post-test-delay 10 --coveralls ${{ secrets.COVERALLS_TOKEN }} || true
+        run: cargo run --release -- tarpaulin --engine llvm --follow-exec --post-test-delay 10 --coveralls ${{ secrets.COVERALLS_TOKEN }} 
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eb68a92..7c5c11b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,12 +6,12 @@ file.
 ## [Unreleased]
 ### Added
 - Working llvm coverage instrumentation (coverage now works on Mac and Windows!)
-- `--post-test-delay` for tests which spawn a process
+- `--post-test-delay` for tests which spawn a process (default 1s for llvm coverage)
 
 ### Changed
 - Update quick-xml to 0.25
 - Make --ignore-tests the default and add a flag --include-tests to reapply the old behaviour
-- profraw files moved to `$TARGET_DIR/tarpaulin/profraws`
+- profraw files moved to `$TARGET_DIR/tarpaulin/profraws` (configurable via `Config::set_profraw_folder`)
 
 ## [0.21.0] 2022-08-30
 ### Changed
diff --git a/Cargo.lock b/Cargo.lock
index 6370bed..e0ddae1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -976,9 +976,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
 
 [[package]]
 name = "syn"
-version = "1.0.101"
+version = "1.0.102"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2"
+checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
 dependencies = [
  "proc-macro2",
  "quote",
diff --git a/src/config/mod.rs b/src/config/mod.rs
index f4fdf5d..6783853 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -184,6 +184,8 @@ pub struct Config {
     #[serde(rename = "post-test-delay")]
     /// Delay after test to collect instrumentation files (LLVM only)
     pub post_test_delay: Option<Duration>,
+    /// Joined to target/tarpaulin to store profraws
+    profraw_folder: PathBuf,
 }
 
 fn default_test_timeout() -> Duration {
@@ -251,7 +253,8 @@ impl Default for Config {
             color: Color::Auto,
             engine: RefCell::default(),
             rustflags: None,
-            post_test_delay: None,
+            post_test_delay: Some(Duration::from_secs(1)),
+            profraw_folder: PathBuf::from("profraws"),
         }
     }
 }
@@ -344,6 +347,7 @@ impl<'a> From<&'a ArgMatches<'a>> for ConfigWrapper {
             implicit_test_threads: args.is_present("implicit-test-threads"),
             rustflags: get_rustflags(args),
             post_test_delay: get_post_test_delay(args),
+            profraw_folder: PathBuf::from("profraws"),
         };
         if args.is_present("ignore-config") {
             Self(vec![args_config])
@@ -426,7 +430,19 @@ impl Config {
 
     /// Get directory profraws are stored in
     pub fn profraw_dir(&self) -> PathBuf {
-        self.target_dir().join("tarpaulin/profraws")
+        if self.profraw_folder.is_relative() {
+            self.target_dir()
+                .join("tarpaulin")
+                .join(&self.profraw_folder)
+        } else {
+            self.profraw_folder.clone()
+        }
+    }
+
+    /// If a relative directory is joined to `$TARGET_DIR/tarpaulin/` otherwise is placed at
+    /// absolute directory location
+    pub fn set_profraw_folder(&mut self, path: PathBuf) {
+        self.profraw_folder = path;
     }
 
     pub fn doctest_dir(&self) -> PathBuf {
diff --git a/src/config/parse.rs b/src/config/parse.rs
index 676b68c..6cd75e5 100644
--- a/src/config/parse.rs
+++ b/src/config/parse.rs
@@ -176,6 +176,7 @@ pub(super) fn get_post_test_delay(args: &ArgMatches) -> Option<Duration> {
         value_t!(args.value_of("post-test-delay"), u64)
             .map(Duration::from_secs)
             .ok()
+            .or_else(|| Some(Duration::from_secs(1)))
     } else {
         None
     }
diff --git a/src/lib.rs b/src/lib.rs
index 4705d86..358ab32 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -62,11 +62,15 @@ pub fn setup_logging(color: Color, debug: bool, verbose: bool) {
 
     let with_ansi = color != Color::Never;
 
-    tracing_subscriber::FmtSubscriber::builder()
+    let res = tracing_subscriber::FmtSubscriber::builder()
         .with_max_level(tracing::Level::ERROR)
         .with_env_filter(filter)
         .with_ansi(with_ansi)
-        .init();
+        .try_init();
+
+    if let Err(e) = res {
+        eprintln!("Logging may be misconfigured: {}", e);
+    }
 
     debug!("set up logging");
 }


Test patch:
diff --git a/tests/doc_coverage.rs b/tests/doc_coverage.rs
index b5a1aa8..7fc10a4 100644
--- a/tests/doc_coverage.rs
+++ b/tests/doc_coverage.rs
@@ -1,13 +1,14 @@
 use crate::utils::get_test_path;
-use cargo_tarpaulin::config::{Config, RunType};
-use cargo_tarpaulin::launch_tarpaulin;
+use cargo_tarpaulin::config::{Color, Config, RunType};
+use cargo_tarpaulin::{launch_tarpaulin, setup_logging};
 use rusty_fork::rusty_fork_test;
-use std::env;
 use std::time::Duration;
+use std::{env, path::PathBuf};
 
 rusty_fork_test! {
 #[test]
 fn doc_test_env() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.set_clean(false);
     config.test_timeout = Duration::from_secs(60);
@@ -15,6 +16,7 @@ fn doc_test_env() {
     env::set_current_dir(&test_dir).unwrap();
     config.manifest = test_dir;
     config.manifest.push("Cargo.toml");
+    config.set_profraw_folder(PathBuf::from("doc_test_env"));
 
     config.run_types = vec![RunType::Doctests];
 
@@ -27,6 +29,7 @@ fn doc_test_env() {
 
 #[test]
 fn doc_test_coverage() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.verbose = true;
     config.set_clean(false);
@@ -37,6 +40,7 @@ fn doc_test_coverage() {
     config.manifest.push("Cargo.toml");
 
     config.run_types = vec![RunType::Doctests];
+    config.set_profraw_folder(PathBuf::from("doc_test_coverage_1"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
 
@@ -45,6 +49,7 @@ fn doc_test_coverage() {
     assert_eq!(res.total_covered(), res.total_coverable());
 
     config.run_types = vec![RunType::Tests];
+    config.set_profraw_folder(PathBuf::from("doc_test_coverage_2"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
 
@@ -54,6 +59,7 @@ fn doc_test_coverage() {
 
 #[test]
 fn doc_test_panics() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.verbose = true;
     config.set_clean(false);
@@ -64,6 +70,7 @@ fn doc_test_panics() {
     config.manifest.push("Cargo.toml");
 
     config.run_types = vec![RunType::Doctests];
+    config.set_profraw_folder(PathBuf::from("doc_test_panics_1"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
 
@@ -72,6 +79,7 @@ fn doc_test_panics() {
     assert_eq!(res.total_covered(), res.total_coverable());
 
     config.run_types = vec![RunType::Tests];
+    config.set_profraw_folder(PathBuf::from("doc_test_panics_2"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
 
@@ -81,6 +89,7 @@ fn doc_test_panics() {
 
 #[test]
 fn doc_test_panics_workspace() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.verbose = true;
     config.set_clean(false);
@@ -89,6 +98,7 @@ fn doc_test_panics_workspace() {
     env::set_current_dir(&test_dir).unwrap();
     config.manifest = test_dir;
     config.manifest.push("Cargo.toml");
+    config.set_profraw_folder(PathBuf::from("doc_test_panics_workspace_1"));
 
     config.run_types = vec![RunType::Doctests];
 
@@ -99,6 +109,7 @@ fn doc_test_panics_workspace() {
     assert_eq!(res.total_covered(), res.total_coverable());
 
     config.run_types = vec![RunType::Tests];
+    config.set_profraw_folder(PathBuf::from("doc_test_panics_workspace_2"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
 
@@ -108,6 +119,7 @@ fn doc_test_panics_workspace() {
 
 #[test]
 fn doc_test_compile_fail() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.verbose = true;
     config.set_clean(false);
@@ -124,6 +136,7 @@ fn doc_test_compile_fail() {
 
 #[test]
 fn doc_test_no_run() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.verbose = true;
     config.set_clean(false);
diff --git a/tests/failure_thresholds.rs b/tests/failure_thresholds.rs
index cfbbf80..7131aa4 100644
--- a/tests/failure_thresholds.rs
+++ b/tests/failure_thresholds.rs
@@ -1,13 +1,17 @@
 use crate::utils::get_test_path;
-use cargo_tarpaulin::run;
-use cargo_tarpaulin::{config::Config, errors::RunError};
+use cargo_tarpaulin::{
+    config::{Color, Config},
+    errors::RunError,
+};
+use cargo_tarpaulin::{run, setup_logging};
 use rusty_fork::rusty_fork_test;
-use std::env;
+use std::{env, path::PathBuf};
 
 rusty_fork_test! {
 
 #[test]
 fn coverage_below_threshold() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     let test_dir = get_test_path("simple_project");
     env::set_current_dir(&test_dir).unwrap();
@@ -15,6 +19,7 @@ fn coverage_below_threshold() {
     config.manifest.push("Cargo.toml");
     config.fail_under = Some(100.0);
     config.set_clean(false);
+    config.set_profraw_folder(PathBuf::from("coverage_below_threshold"));
 
     let result = run(&[config]);
 
@@ -29,6 +34,7 @@ fn coverage_below_threshold() {
 
 #[test]
 fn coverage_above_threshold() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     let test_dir = get_test_path("simple_project");
     env::set_current_dir(&test_dir).unwrap();
@@ -36,6 +42,7 @@ fn coverage_above_threshold() {
     config.manifest.push("Cargo.toml");
     config.fail_under = Some(30.0);
     config.set_clean(false);
+    config.set_profraw_folder(PathBuf::from("coverage_above_threshold"));
 
     let result = run(&[config]);
 
@@ -44,6 +51,7 @@ fn coverage_above_threshold() {
 
 #[test]
 fn report_coverage_fail() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     let test_dir = get_test_path("simple_project");
     env::set_current_dir(&test_dir).unwrap();
@@ -51,6 +59,7 @@ fn report_coverage_fail() {
     config.manifest.push("Cargo.toml");
     config.fail_under = Some(10.0);
     config.set_clean(false);
+    config.set_profraw_folder(PathBuf::from("report_coverage_fail"));
 
     let mut report = Config::default();
     report.name = "report".to_string();
diff --git a/tests/failures.rs b/tests/failures.rs
index f1005cb..db6fe9f 100644
--- a/tests/failures.rs
+++ b/tests/failures.rs
@@ -1,9 +1,9 @@
 use crate::utils::get_test_path;
 use cargo_tarpaulin::{
-    config::{Config, Mode},
+    config::{Color, Config, Mode},
     errors::RunError,
 };
-use cargo_tarpaulin::{launch_tarpaulin, run};
+use cargo_tarpaulin::{launch_tarpaulin, run, setup_logging};
 use rusty_fork::rusty_fork_test;
 use std::env;
 
@@ -11,6 +11,7 @@ rusty_fork_test! {
 
 #[test]
 fn error_if_build_script_fails() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     let test_dir = get_test_path("build_script_fail");
     env::set_current_dir(&test_dir).unwrap();
@@ -30,6 +31,7 @@ fn error_if_build_script_fails() {
 
 #[test]
 fn error_if_compilation_fails() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     let test_dir = get_test_path("compile_fail");
     env::set_current_dir(&test_dir).unwrap();
@@ -49,6 +51,7 @@ fn error_if_compilation_fails() {
 
 #[test]
 fn error_if_test_fails() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     let test_dir = get_test_path("failing_test");
     env::set_current_dir(&test_dir).unwrap();
@@ -68,6 +71,7 @@ fn error_if_test_fails() {
 
 #[test]
 fn issue_610() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     let test_dir = get_test_path("issue_610");
     config.test_names.insert("foo".to_string());
diff --git a/tests/line_coverage.rs b/tests/line_coverage.rs
index 62fa5fe..02d7225 100644
--- a/tests/line_coverage.rs
+++ b/tests/line_coverage.rs
@@ -1,7 +1,7 @@
 use crate::utils::get_test_path;
-use cargo_tarpaulin::config::Config;
-use cargo_tarpaulin::launch_tarpaulin;
+use cargo_tarpaulin::config::{Color, Config};
 use cargo_tarpaulin::traces::CoverageStat;
+use cargo_tarpaulin::{launch_tarpaulin, setup_logging};
 use rusty_fork::rusty_fork_test;
 use std::env;
 use std::time::Duration;
@@ -10,6 +10,7 @@ rusty_fork_test! {
 
 #[test]
 fn simple_project_coverage() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.set_clean(false);
     config.test_timeout = Duration::from_secs(60);
@@ -50,6 +51,7 @@ fn simple_project_coverage() {
 
 #[test]
 fn debug_info_0() {
+    setup_logging(Color::Never, false, false);
     // From issue #601
     let mut config = Config::default();
     config.set_clean(false);
@@ -72,6 +74,7 @@ fn debug_info_0() {
 
 #[test]
 fn test_threads_1() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.set_clean(false);
     let restore_dir = env::current_dir().unwrap();
diff --git a/tests/mod.rs b/tests/mod.rs
index 1e49493..343604f 100644
--- a/tests/mod.rs
+++ b/tests/mod.rs
@@ -1,15 +1,15 @@
 use crate::utils::get_test_path;
-use cargo_tarpaulin::config::{Config, ConfigWrapper, Mode, RunType, TraceEngine};
+use cargo_tarpaulin::config::{Color, Config, ConfigWrapper, Mode, RunType, TraceEngine};
 use cargo_tarpaulin::event_log::EventLog;
-use cargo_tarpaulin::launch_tarpaulin;
 use cargo_tarpaulin::path_utils::*;
 use cargo_tarpaulin::traces::TraceMap;
+use cargo_tarpaulin::{launch_tarpaulin, setup_logging};
 use clap::App;
 use rusty_fork::rusty_fork_test;
 use std::collections::HashSet;
 use std::env;
 use std::fs;
-use std::path::Path;
+use std::path::{Path, PathBuf};
 use std::time::Duration;
 
 #[cfg(nightly)]
@@ -22,6 +22,7 @@ mod utils;
 mod workspaces;
 
 pub fn check_percentage_with_cli_args(minimum_coverage: f64, has_lines: bool, args: &[String]) {
+    setup_logging(Color::Never, false, false);
     let restore_dir = env::current_dir().unwrap();
     let matches = App::new("tarpaulin")
         .args_from_usage(
@@ -61,6 +62,7 @@ pub fn check_percentage_with_config(
     has_lines: bool,
     mut config: Config,
 ) {
+    setup_logging(Color::Never, false, false);
     config.test_timeout = Duration::from_secs(60);
     let restore_dir = env::current_dir().unwrap();
     let test_dir = get_test_path(project_name);
@@ -190,7 +192,6 @@ fn paths_coverage() {
 }
 
 #[test]
-#[cfg(not(tarpaulin))]
 fn futures_coverage() {
     check_percentage("futures", 1.0f64, true);
 }
@@ -322,7 +323,6 @@ fn filter_with_inner_attributes() {
 }
 
 #[test]
-#[cfg(not(tarpaulin))]
 fn cargo_home_filtering() {
     let new_home =
         Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/data/HttptestAndReqwest/new_home");
diff --git a/tests/test_types.rs b/tests/test_types.rs
index 83613e2..640c573 100644
--- a/tests/test_types.rs
+++ b/tests/test_types.rs
@@ -1,14 +1,16 @@
 use crate::utils::get_test_path;
-use cargo_tarpaulin::config::{types::RunType, Config};
-use cargo_tarpaulin::launch_tarpaulin;
+use cargo_tarpaulin::config::{types::RunType, Color, Config};
+use cargo_tarpaulin::{launch_tarpaulin, setup_logging};
 use rusty_fork::rusty_fork_test;
 use std::env;
+use std::path::PathBuf;
 use std::time::Duration;
 
 rusty_fork_test! {
 
 #[test]
 fn mix_test_types() {
+    setup_logging(Color::Never, false, false);
     // Issue 747 the clean would delete old tests leaving to only one run type effectively being
     // ran. This test covers against that mistake
     let mut config = Config::default();
@@ -16,6 +18,8 @@ fn mix_test_types() {
     config.set_ignore_tests(false);
     config.test_timeout = Duration::from_secs(60);
     config.run_types = vec![RunType::Tests, RunType::Examples];
+    config.set_profraw_folder(PathBuf::from("mix_test_types"));
+
     let restore_dir = env::current_dir().unwrap();
     let test_dir = get_test_path("all_test_types");
     env::set_current_dir(&test_dir).unwrap();
@@ -38,6 +42,7 @@ fn mix_test_types() {
 
 #[test]
 fn only_test_coverage() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.set_clean(false);
     config.test_timeout = Duration::from_secs(60);
@@ -47,6 +52,7 @@ fn only_test_coverage() {
     env::set_current_dir(&test_dir).unwrap();
     config.manifest = test_dir;
     config.manifest.push("Cargo.toml");
+    config.set_profraw_folder(PathBuf::from("only_test_coverage"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
     assert_eq!(ret, 0);
@@ -64,6 +70,7 @@ fn only_test_coverage() {
 
 #[test]
 fn only_example_coverage() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.set_clean(false);
     config.test_timeout = Duration::from_secs(60);
@@ -73,6 +80,7 @@ fn only_example_coverage() {
     env::set_current_dir(&test_dir).unwrap();
     config.manifest = test_dir;
     config.manifest.push("Cargo.toml");
+    config.set_profraw_folder(PathBuf::from("only_example_coverage"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
     assert_eq!(ret, 0);
@@ -91,6 +99,7 @@ fn only_example_coverage() {
 #[test]
 #[ignore]
 fn only_bench_coverage() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.set_clean(false);
     config.test_timeout = Duration::from_secs(60);
@@ -100,6 +109,7 @@ fn only_bench_coverage() {
     env::set_current_dir(&test_dir).unwrap();
     config.manifest = test_dir;
     config.manifest.push("Cargo.toml");
+    config.set_profraw_folder(PathBuf::from("only_bench_coverage"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
     assert_eq!(ret, 0);
@@ -118,6 +128,7 @@ fn only_bench_coverage() {
 #[test]
 #[cfg(feature = "nightly")]
 fn only_doctest_coverage() {
+    setup_logging(Color::Never, false, false);
     let mut config = Config::default();
     config.set_clean(false);
     config.test_timeout = Duration::from_secs(60);
@@ -127,6 +138,7 @@ fn only_doctest_coverage() {
     env::set_current_dir(&test_dir).unwrap();
     config.manifest = test_dir;
     config.manifest.push("Cargo.toml");
+    config.set_profraw_folder(PathBuf::from("only_doctest_coverage"));
 
     let (res, ret) = launch_tarpaulin(&config, &None).unwrap();
     assert_eq!(ret, 0);