Repository: xd009642/tarpaulin
Pull request #1552 (2024-05-19 16:42:46)

FIll in some gaps in testing, refactor
<!--- 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/src/config/mod.rs b/src/config/mod.rs
index eac6d0c..0495edf 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -2,7 +2,7 @@ use self::parse::*;
 pub use self::types::*;
 use crate::path_utils::fix_unc_path;
 use crate::{args::ConfigArgs, cargo::supports_llvm_coverage};
-use cargo_metadata::{Metadata, MetadataCommand, Package};
+use cargo_metadata::{Metadata, MetadataCommand};
 use coveralls_api::CiService;
 use glob::Pattern;
 use humantime_serde::deserialize as humantime_serde;
@@ -487,13 +487,6 @@ impl Config {
         self.manifest = manifest;
     }
 
-    pub fn get_packages(&self) -> Vec<Package> {
-        match *self.get_metadata() {
-            Some(ref meta) => meta.packages.clone(),
-            None => vec![],
-        }
-    }
-
     pub fn output_dir(&self) -> PathBuf {
         let path = if let Some(ref path) = self.output_directory {
             if path.is_relative() {
diff --git a/src/errors/mod.rs b/src/errors/mod.rs
index 176ba23..13973ea 100644
--- a/src/errors/mod.rs
+++ b/src/errors/mod.rs
@@ -1,3 +1,4 @@
+#![cfg(not(tarpaulin_include))]
 use crate::report::cobertura;
 use std::fmt::{self, Display, Formatter};
 
diff --git a/src/lib.rs b/src/lib.rs
index 7a707a7..dad33e5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,6 +28,7 @@ pub mod traces;
 
 const RUST_LOG_ENV: &str = "RUST_LOG";
 
+#[cfg(not(tarpaulin_include))]
 pub fn setup_logging(color: Color, debug: bool, verbose: bool) {
     //By default, we set tarpaulin to info,debug,trace while all dependencies stay at INFO
     let base_exceptions = |env: EnvFilter| {
diff --git a/src/statemachine/mod.rs b/src/statemachine/mod.rs
index ef104b8..2e30358 100644
--- a/src/statemachine/mod.rs
+++ b/src/statemachine/mod.rs
@@ -31,11 +31,12 @@ pub fn create_state_machine<'a>(
                     (state, Box::new(machine))
                 } else {
                     error!("The ptrace backend is not supported on this system");
-                    (TestState::End(1), Box::new(()))
+                    panic!()
                 }
             }
         }
-        TraceEngine::Llvm => {
+        // Should never be auto so ignore our normal rules
+        TraceEngine::Llvm | TraceEngine::Auto => {
             let (state, machine) = instrumented::create_state_machine(
                 test,
                 traces,
@@ -45,10 +46,6 @@ pub fn create_state_machine<'a>(
             );
             (state, Box::new(machine))
         }
-        _ => {
-            error!("Tarpaulin is not currently supported on this system");
-            (TestState::End(1), Box::new(()))
-        }
     }
 }
 
@@ -115,34 +112,6 @@ pub trait StateData {
     fn stop(&mut self) -> Result<TestState, RunError>;
 }
 
-impl StateData for () {
-    fn start(&mut self) -> Result<Option<TestState>, RunError> {
-        Err(RunError::StateMachine(
-            "No valid coverage collector".to_string(),
-        ))
-    }
-    fn init(&mut self) -> Result<TestState, RunError> {
-        Err(RunError::StateMachine(
-            "No valid coverage collector".to_string(),
-        ))
-    }
-    fn wait(&mut self) -> Result<Option<TestState>, RunError> {
-        Err(RunError::StateMachine(
-            "No valid coverage collector".to_string(),
-        ))
-    }
-    fn last_wait_attempt(&mut self) -> Result<Option<TestState>, RunError> {
-        Err(RunError::StateMachine(
-            "No valid coverage collector".to_string(),
-        ))
-    }
-    fn stop(&mut self) -> Result<TestState, RunError> {
-        Err(RunError::StateMachine(
-            "No valid coverage collector".to_string(),
-        ))
-    }
-}
-
 impl<'a> StateData for Box<dyn StateData + 'a> {
     fn start(&mut self) -> Result<Option<TestState>, RunError> {
         self.as_mut().start()
@@ -220,3 +189,52 @@ impl TestState {
         }
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::time::Duration;
+
+    impl StateData for () {
+        fn start(&mut self) -> Result<Option<TestState>, RunError> {
+            Ok(None)
+        }
+
+        fn init(&mut self) -> Result<TestState, RunError> {
+            Err(RunError::StateMachine(
+                "No valid coverage collector".to_string(),
+            ))
+        }
+
+        fn wait(&mut self) -> Result<Option<TestState>, RunError> {
+            Ok(None)
+        }
+
+        fn last_wait_attempt(&mut self) -> Result<Option<TestState>, RunError> {
+            Err(RunError::StateMachine(
+                "No valid coverage collector".to_string(),
+            ))
+        }
+        fn stop(&mut self) -> Result<TestState, RunError> {
+            Err(RunError::StateMachine(
+                "No valid coverage collector".to_string(),
+            ))
+        }
+    }
+
+    #[test]
+    fn hits_timeouts() {
+        let mut config = Config::default();
+        config.test_timeout = Duration::from_secs(5);
+
+        let start_time = Instant::now() - Duration::from_secs(6);
+
+        let state = TestState::Start { start_time };
+
+        assert!(state.step(&mut (), &config).is_err());
+
+        let state = TestState::Waiting { start_time };
+
+        assert!(state.step(&mut (), &config).is_err());
+    }
+}


Test patch:
diff --git a/tests/mod.rs b/tests/mod.rs
index e7770d2..df1b616 100755
--- a/tests/mod.rs
+++ b/tests/mod.rs
@@ -182,6 +182,15 @@ fn llvm_sanity_test() {
     check_percentage_with_config("follow_exe", 1.0f64, true, config);
 }
 
+#[cfg_attr(not(ptrace_supported), test)]
+#[should_panic]
+fn ptrace_not_unsupported_system() {
+    let config = Config::default();
+    config.set_engine(TraceEngine::Ptrace);
+
+    run_config("simple_project", config);
+}
+
 #[test]
 fn struct_expr_coverage() {
     check_percentage("structs", 1.0f64, true);