@@ -12,7 +12,7 @@ use std::process::{self, Command, Stdio};
12
12
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
13
13
use std:: sync:: { Arc , Mutex } ;
14
14
use std:: time:: { Duration , Instant } ;
15
- use std:: { fmt , panic, str} ;
15
+ use std:: { panic, str} ;
16
16
17
17
pub ( crate ) use make:: { BuildDocTestBuilder , DocTestBuilder } ;
18
18
pub ( crate ) use markdown:: test as test_markdown;
@@ -60,24 +60,15 @@ impl MergedDoctestTimes {
60
60
self . added_compilation_times += 1 ;
61
61
}
62
62
63
- fn display_times ( & self ) {
63
+ /// Returns `(total_time, compilation_time)`.
64
+ fn times_in_secs ( & self ) -> Option < ( f64 , f64 ) > {
64
65
// If no merged doctest was compiled, then there is nothing to display since the numbers
65
66
// displayed by `libtest` for standalone tests are already accurate (they include both
66
67
// compilation and runtime).
67
- if self . added_compilation_times > 0 {
68
- println ! ( "{self}" ) ;
68
+ if self . added_compilation_times == 0 {
69
+ return None ;
69
70
}
70
- }
71
- }
72
-
73
- impl fmt:: Display for MergedDoctestTimes {
74
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
75
- write ! (
76
- f,
77
- "all doctests ran in {:.2}s; merged doctests compilation took {:.2}s" ,
78
- self . total_time. elapsed( ) . as_secs_f64( ) ,
79
- self . compilation_time. as_secs_f64( ) ,
80
- )
71
+ Some ( ( self . total_time . elapsed ( ) . as_secs_f64 ( ) , self . compilation_time . as_secs_f64 ( ) ) )
81
72
}
82
73
}
83
74
@@ -400,15 +391,21 @@ pub(crate) fn run_tests(
400
391
if ran_edition_tests == 0 || !standalone_tests. is_empty ( ) {
401
392
standalone_tests. sort_by ( |a, b| a. desc . name . as_slice ( ) . cmp ( b. desc . name . as_slice ( ) ) ) ;
402
393
test:: test_main_with_exit_callback ( & test_args, standalone_tests, None , || {
394
+ let times = times. times_in_secs ( ) ;
403
395
// We ensure temp dir destructor is called.
404
396
std:: mem:: drop ( temp_dir. take ( ) ) ;
405
- times. display_times ( ) ;
397
+ if let Some ( ( total_time, compilation_time) ) = times {
398
+ test:: print_merged_doctests_times ( & test_args, total_time, compilation_time) ;
399
+ }
406
400
} ) ;
407
401
}
402
+ let times = times. times_in_secs ( ) ;
403
+ // We ensure temp dir destructor is called.
404
+ std:: mem:: drop ( temp_dir) ;
405
+ if let Some ( ( total_time, compilation_time) ) = times {
406
+ test:: print_merged_doctests_times ( & test_args, total_time, compilation_time) ;
407
+ }
408
408
if nb_errors != 0 {
409
- // We ensure temp dir destructor is called.
410
- std:: mem:: drop ( temp_dir) ;
411
- times. display_times ( ) ;
412
409
// FIXME(GuillaumeGomez): Uncomment the next line once #144297 has been merged.
413
410
// std::process::exit(test::ERROR_EXIT_CODE);
414
411
std:: process:: exit ( 101 ) ;
0 commit comments