]> git.lizzy.rs Git - rust.git/commitdiff
Make interface of the feature more convenient
authorIgor Aleksanov <popzxc@yandex.ru>
Wed, 9 Oct 2019 07:03:08 +0000 (10:03 +0300)
committerIgor Aleksanov <popzxc@yandex.ru>
Wed, 9 Oct 2019 07:03:08 +0000 (10:03 +0300)
src/libtest/formatters/pretty.rs
src/libtest/lib.rs

index 58824a3952ac0ae08f79bc896a1414b272e89fe8..2935b4c99cec42c68f76e5c1c0acc1cd6a1f3d58 100644 (file)
@@ -209,7 +209,7 @@ fn write_result(
             TrAllowedFail => self.write_allowed_fail()?,
             TrBench(ref bs) => {
                 self.write_bench()?;
             TrAllowedFail => self.write_allowed_fail()?,
             TrBench(ref bs) => {
                 self.write_bench()?;
-                self.write_plain(&format!(": {}\n", fmt_bench_samples(bs)))?;
+                self.write_plain(&format!(": {}", fmt_bench_samples(bs)))?;
             }
             TrTimedFail => self.write_time_failed()?,
         }
             }
             TrTimedFail => self.write_time_failed()?,
         }
index c303c19952265c04ad5cb48c5594ab16de1c60bc..60bd088ea427d2b60c6d3aebbeb8ebc9921e1bbe 100644 (file)
@@ -514,6 +514,10 @@ pub fn from_env_var(env_var_name: &str) -> Option<Self> {
             durations.next().unwrap_or_else(panic_on_incorrect_value)
         );
 
             durations.next().unwrap_or_else(panic_on_incorrect_value)
         );
 
+        if warn > critical {
+            panic!("Test execution warn time should be less or equal to the critical time");
+        }
+
         Some(Self::new(Duration::from_millis(warn), Duration::from_millis(critical)))
     }
 }
         Some(Self::new(Duration::from_millis(warn), Duration::from_millis(critical)))
     }
 }
@@ -704,17 +708,24 @@ fn optgroups() -> getopts::Options {
             `RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` and
             `RUST_TEST_TIME_DOCTEST` environment variables.
 
             `RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` and
             `RUST_TEST_TIME_DOCTEST` environment variables.
 
+            Expected format of environment variable is `VARIABLE=WARN_TIME,CRITICAL_TIME`.
+
             Not available for --format=terse",
             "plain|colored"
         )
         .optflag(
             "",
             Not available for --format=terse",
             "plain|colored"
         )
         .optflag(
             "",
-            "ensure-test-time",
+            "ensure-time",
             "Treat excess of the test execution time limit as error.
 
             Threshold values for this option can be configured via
             `RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` and
             "Treat excess of the test execution time limit as error.
 
             Threshold values for this option can be configured via
             `RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` and
-            `RUST_TEST_TIME_DOCTEST` environment variables."
+            `RUST_TEST_TIME_DOCTEST` environment variables.
+
+            Expected format of environment variable is `VARIABLE=WARN_TIME,CRITICAL_TIME`.
+
+            `CRITICAL_TIME` here means the limit that should not be exceeded by test.
+            "
         );
     return opts;
 }
         );
     return opts;
 }
@@ -785,12 +796,15 @@ fn get_time_options(
 -> Option<OptPartRes<TestTimeOptions>> {
     let report_time = unstable_optflag!(matches, allow_unstable, "report-time");
     let colored_opt_str = matches.opt_str("report-time");
 -> Option<OptPartRes<TestTimeOptions>> {
     let report_time = unstable_optflag!(matches, allow_unstable, "report-time");
     let colored_opt_str = matches.opt_str("report-time");
-    let report_time_colored = report_time && colored_opt_str == Some("colored".into());
-    let ensure_test_time = unstable_optflag!(matches, allow_unstable, "ensure-test-time");
+    let mut report_time_colored = report_time && colored_opt_str == Some("colored".into());
+    let ensure_test_time = unstable_optflag!(matches, allow_unstable, "ensure-time");
 
     // If `ensure-test-time` option is provided, time output is enforced,
     // so user won't be confused if any of tests will silently fail.
     let options = if report_time || ensure_test_time {
 
     // If `ensure-test-time` option is provided, time output is enforced,
     // so user won't be confused if any of tests will silently fail.
     let options = if report_time || ensure_test_time {
+        if ensure_test_time && !report_time {
+            report_time_colored = true;
+        }
         Some(TestTimeOptions::new_from_env(ensure_test_time, report_time_colored))
     } else {
         None
         Some(TestTimeOptions::new_from_env(ensure_test_time, report_time_colored))
     } else {
         None
@@ -872,7 +886,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
     let time_options = match get_time_options(&matches, allow_unstable) {
         Some(Ok(val)) => val,
         Some(Err(e)) => return Some(Err(e)),
     let time_options = match get_time_options(&matches, allow_unstable) {
         Some(Ok(val)) => val,
         Some(Err(e)) => return Some(Err(e)),
-        x => panic!("Unexpected output from `get_time_options`: {:?}", x),
+        None => panic!("Unexpected output from `get_time_options`"),
     };
 
     let test_threads = match matches.opt_str("test-threads") {
     };
 
     let test_threads = match matches.opt_str("test-threads") {