@@ -12,7 +12,7 @@ use std::process::{self, Command, Stdio};
1212use  std:: sync:: atomic:: { AtomicUsize ,  Ordering } ; 
1313use  std:: sync:: { Arc ,  Mutex } ; 
1414use  std:: time:: { Duration ,  Instant } ; 
15- use  std:: { fmt ,   panic,  str} ; 
15+ use  std:: { panic,  str} ; 
1616
1717pub ( crate )  use  make:: { BuildDocTestBuilder ,  DocTestBuilder } ; 
1818pub ( crate )  use  markdown:: test as  test_markdown; 
@@ -60,24 +60,15 @@ impl MergedDoctestTimes {
6060        self . added_compilation_times  += 1 ; 
6161    } 
6262
63-     fn  display_times ( & self )  { 
63+     /// Returns `(total_time, compilation_time)`. 
64+ fn  times_in_secs ( & self )  -> Option < ( f64 ,  f64 ) >  { 
6465        // If no merged doctest was compiled, then there is nothing to display since the numbers 
6566        // displayed by `libtest` for standalone tests are already accurate (they include both 
6667        // compilation and runtime). 
67-         if  self . added_compilation_times  >  0  { 
68-             println ! ( "{self}" ) ; 
68+         if  self . added_compilation_times  ==  0  { 
69+             return   None ; 
6970        } 
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 ( ) ) ) 
8172    } 
8273} 
8374
@@ -402,15 +393,20 @@ pub(crate) fn run_tests(
402393    if  ran_edition_tests == 0  || !standalone_tests. is_empty ( )  { 
403394        standalone_tests. sort_by ( |a,  b| a. desc . name . as_slice ( ) . cmp ( b. desc . name . as_slice ( ) ) ) ; 
404395        test:: test_main_with_exit_callback ( & test_args,  standalone_tests,  None ,  || { 
396+             let  times = times. times_in_secs ( ) ; 
405397            // We ensure temp dir destructor is called. 
406398            std:: mem:: drop ( temp_dir. take ( ) ) ; 
407-             times. display_times ( ) ; 
399+             if  let  Some ( ( total_time,  compilation_time) )  = times { 
400+                 test:: print_merged_doctests_times ( & test_args,  total_time,  compilation_time) ; 
401+             } 
408402        } ) ; 
409403    }  else  { 
410404        // If the first condition branch exited successfully, `test_main_with_exit_callback` will 
411405        // not exit the process. So to prevent displaying the times twice, we put it behind an 
412406        // `else` condition. 
413-         times. display_times ( ) ; 
407+         if  let  Some ( ( total_time,  compilation_time) )  = times. times_in_secs ( )  { 
408+             test:: print_merged_doctests_times ( & test_args,  total_time,  compilation_time) ; 
409+         } 
414410    } 
415411    // We ensure temp dir destructor is called. 
416412    std:: mem:: drop ( temp_dir) ; 
0 commit comments