Skip to content

Commit 375a051

Browse files
committed
Make interface of the feature more convenient
1 parent 8231f46 commit 375a051

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/libtest/formatters/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
209209
TrAllowedFail => self.write_allowed_fail()?,
210210
TrBench(ref bs) => {
211211
self.write_bench()?;
212-
self.write_plain(&format!(": {}\n", fmt_bench_samples(bs)))?;
212+
self.write_plain(&format!(": {}", fmt_bench_samples(bs)))?;
213213
}
214214
TrTimedFail => self.write_time_failed()?,
215215
}

src/libtest/lib.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ impl TimeThreshold {
514514
durations.next().unwrap_or_else(panic_on_incorrect_value)
515515
);
516516

517+
if warn > critical {
518+
panic!("Test execution warn time should be less or equal to the critical time");
519+
}
520+
517521
Some(Self::new(Duration::from_millis(warn), Duration::from_millis(critical)))
518522
}
519523
}
@@ -704,17 +708,24 @@ fn optgroups() -> getopts::Options {
704708
`RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` and
705709
`RUST_TEST_TIME_DOCTEST` environment variables.
706710
711+
Expected format of environment variable is `VARIABLE=WARN_TIME,CRITICAL_TIME`.
712+
707713
Not available for --format=terse",
708714
"plain|colored"
709715
)
710716
.optflag(
711717
"",
712-
"ensure-test-time",
718+
"ensure-time",
713719
"Treat excess of the test execution time limit as error.
714720
715721
Threshold values for this option can be configured via
716722
`RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` and
717-
`RUST_TEST_TIME_DOCTEST` environment variables."
723+
`RUST_TEST_TIME_DOCTEST` environment variables.
724+
725+
Expected format of environment variable is `VARIABLE=WARN_TIME,CRITICAL_TIME`.
726+
727+
`CRITICAL_TIME` here means the limit that should not be exceeded by test.
728+
"
718729
);
719730
return opts;
720731
}
@@ -785,12 +796,15 @@ fn get_time_options(
785796
-> Option<OptPartRes<TestTimeOptions>> {
786797
let report_time = unstable_optflag!(matches, allow_unstable, "report-time");
787798
let colored_opt_str = matches.opt_str("report-time");
788-
let report_time_colored = report_time && colored_opt_str == Some("colored".into());
789-
let ensure_test_time = unstable_optflag!(matches, allow_unstable, "ensure-test-time");
799+
let mut report_time_colored = report_time && colored_opt_str == Some("colored".into());
800+
let ensure_test_time = unstable_optflag!(matches, allow_unstable, "ensure-time");
790801

791802
// If `ensure-test-time` option is provided, time output is enforced,
792803
// so user won't be confused if any of tests will silently fail.
793804
let options = if report_time || ensure_test_time {
805+
if ensure_test_time && !report_time {
806+
report_time_colored = true;
807+
}
794808
Some(TestTimeOptions::new_from_env(ensure_test_time, report_time_colored))
795809
} else {
796810
None
@@ -872,7 +886,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
872886
let time_options = match get_time_options(&matches, allow_unstable) {
873887
Some(Ok(val)) => val,
874888
Some(Err(e)) => return Some(Err(e)),
875-
x => panic!("Unexpected output from `get_time_options`: {:?}", x),
889+
None => panic!("Unexpected output from `get_time_options`"),
876890
};
877891

878892
let test_threads = match matches.opt_str("test-threads") {

0 commit comments

Comments
 (0)