]> git.lizzy.rs Git - rust.git/blobdiff - src/libtest/time.rs
Rollup merge of #69568 - JOE1994:patch-2, r=Dylan-DPC
[rust.git] / src / libtest / time.rs
index f4d4b17b620ba7c467f8171a26d60721291943ac..96c090f9b016370aefa623dfb1d42ea38aedaae0 100644 (file)
@@ -4,10 +4,10 @@
 //! - Check whether test is timed out.
 //! - Provide helpers for `report-time` and `measure-time` options.
 
-use std::time::{Duration, Instant};
-use std::str::FromStr;
-use std::fmt;
 use std::env;
+use std::fmt;
+use std::str::FromStr;
+use std::time::{Duration, Instant};
 
 use super::types::{TestDesc, TestType};
 
@@ -23,8 +23,8 @@
 /// Example of the expected format is `RUST_TEST_TIME_xxx=100,200`, where 100 means
 /// warn time, and 200 means critical time.
 pub mod time_constants {
-    use std::time::Duration;
     use super::TEST_WARN_TIMEOUT_S;
+    use std::time::Duration;
 
     /// Environment variable for overriding default threshold for unit-tests.
     pub const UNIT_ENV_NAME: &str = "RUST_TEST_TIME_UNIT";
@@ -80,10 +80,7 @@ pub struct TimeThreshold {
 impl TimeThreshold {
     /// Creates a new `TimeThreshold` instance with provided durations.
     pub fn new(warn: Duration, critical: Duration) -> Self {
-        Self {
-            warn,
-            critical,
-        }
+        Self { warn, critical }
     }
 
     /// Attempts to create a `TimeThreshold` instance with values obtained
@@ -99,16 +96,14 @@ pub fn from_env_var(env_var_name: &str) -> Option<Self> {
         let durations_str = env::var(env_var_name).ok()?;
 
         // Split string into 2 substrings by comma and try to parse numbers.
-        let mut durations = durations_str
-            .splitn(2, ',')
-            .map(|v| {
-                u64::from_str(v).unwrap_or_else(|_| {
-                    panic!(
-                        "Duration value in variable {} is expected to be a number, but got {}",
-                        env_var_name, v
-                    )
-                })
-            });
+        let mut durations = durations_str.splitn(2, ',').map(|v| {
+            u64::from_str(v).unwrap_or_else(|_| {
+                panic!(
+                    "Duration value in variable {} is expected to be a number, but got {}",
+                    env_var_name, v
+                )
+            })
+        });
 
         // Callback to be called if the environment variable has unexpected structure.
         let panic_on_incorrect_value = || {
@@ -120,7 +115,7 @@ pub fn from_env_var(env_var_name: &str) -> Option<Self> {
 
         let (warn, critical) = (
             durations.next().unwrap_or_else(panic_on_incorrect_value),
-            durations.next().unwrap_or_else(panic_on_incorrect_value)
+            durations.next().unwrap_or_else(panic_on_incorrect_value),
         );
 
         if warn > critical {
@@ -145,25 +140,17 @@ pub struct TestTimeOptions {
 
 impl TestTimeOptions {
     pub fn new_from_env(error_on_excess: bool, colored: bool) -> Self {
-        let unit_threshold =
-            TimeThreshold::from_env_var(time_constants::UNIT_ENV_NAME)
-                .unwrap_or_else(Self::default_unit);
+        let unit_threshold = TimeThreshold::from_env_var(time_constants::UNIT_ENV_NAME)
+            .unwrap_or_else(Self::default_unit);
 
         let integration_threshold =
             TimeThreshold::from_env_var(time_constants::INTEGRATION_ENV_NAME)
                 .unwrap_or_else(Self::default_integration);
 
-        let doctest_threshold =
-            TimeThreshold::from_env_var(time_constants::DOCTEST_ENV_NAME)
-                .unwrap_or_else(Self::default_doctest);
+        let doctest_threshold = TimeThreshold::from_env_var(time_constants::DOCTEST_ENV_NAME)
+            .unwrap_or_else(Self::default_doctest);
 
-        Self {
-            error_on_excess,
-            colored,
-            unit_threshold,
-            integration_threshold,
-            doctest_threshold,
-        }
+        Self { error_on_excess, colored, unit_threshold, integration_threshold, doctest_threshold }
     }
 
     pub fn is_warn(&self, test: &TestDesc, exec_time: &TestExecTime) -> bool {