@@ -514,6 +514,10 @@ impl TimeThreshold {
514
514
durations. next ( ) . unwrap_or_else ( panic_on_incorrect_value)
515
515
) ;
516
516
517
+ if warn > critical {
518
+ panic ! ( "Test execution warn time should be less or equal to the critical time" ) ;
519
+ }
520
+
517
521
Some ( Self :: new ( Duration :: from_millis ( warn) , Duration :: from_millis ( critical) ) )
518
522
}
519
523
}
@@ -704,17 +708,24 @@ fn optgroups() -> getopts::Options {
704
708
`RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` and
705
709
`RUST_TEST_TIME_DOCTEST` environment variables.
706
710
711
+ Expected format of environment variable is `VARIABLE=WARN_TIME,CRITICAL_TIME`.
712
+
707
713
Not available for --format=terse" ,
708
714
"plain|colored"
709
715
)
710
716
. optflag (
711
717
"" ,
712
- "ensure-test- time" ,
718
+ "ensure-time" ,
713
719
"Treat excess of the test execution time limit as error.
714
720
715
721
Threshold values for this option can be configured via
716
722
`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
+ "
718
729
) ;
719
730
return opts;
720
731
}
@@ -785,12 +796,15 @@ fn get_time_options(
785
796
-> Option < OptPartRes < TestTimeOptions > > {
786
797
let report_time = unstable_optflag ! ( matches, allow_unstable, "report-time" ) ;
787
798
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" ) ;
790
801
791
802
// If `ensure-test-time` option is provided, time output is enforced,
792
803
// so user won't be confused if any of tests will silently fail.
793
804
let options = if report_time || ensure_test_time {
805
+ if ensure_test_time && !report_time {
806
+ report_time_colored = true ;
807
+ }
794
808
Some ( TestTimeOptions :: new_from_env ( ensure_test_time, report_time_colored) )
795
809
} else {
796
810
None
@@ -872,7 +886,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
872
886
let time_options = match get_time_options ( & matches, allow_unstable) {
873
887
Some ( Ok ( val) ) => val,
874
888
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`" ) ,
876
890
} ;
877
891
878
892
let test_threads = match matches. opt_str ( "test-threads" ) {
0 commit comments