@@ -304,13 +304,14 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
304
304
test_main ( & args, owned_tests)
305
305
}
306
306
307
- #[ derive( Copy , Clone ) ]
307
+ #[ derive( Copy , Clone , Debug ) ]
308
308
pub enum ColorConfig {
309
309
AutoColor ,
310
310
AlwaysColor ,
311
311
NeverColor ,
312
312
}
313
313
314
+ #[ derive( Debug ) ]
314
315
pub struct TestOpts {
315
316
pub list : bool ,
316
317
pub filter : Option < String > ,
@@ -324,6 +325,7 @@ pub struct TestOpts {
324
325
pub quiet : bool ,
325
326
pub test_threads : Option < usize > ,
326
327
pub skip : Vec < String > ,
328
+ pub display_stdout : bool ,
327
329
}
328
330
329
331
impl TestOpts {
@@ -342,6 +344,7 @@ impl TestOpts {
342
344
quiet : false ,
343
345
test_threads : None ,
344
346
skip : vec ! [ ] ,
347
+ display_stdout : false ,
345
348
}
346
349
}
347
350
}
@@ -369,7 +372,8 @@ fn optgroups() -> Vec<getopts::OptGroup> {
369
372
getopts:: optopt( "" , "color" , "Configure coloring of output:
370
373
auto = colorize if stdout is a tty and tests are run on serially (default);
371
374
always = always colorize output;
372
- never = never colorize output;" , "auto|always|never" ) ]
375
+ never = never colorize output;" , "auto|always|never" ) ,
376
+ getopts:: optflag( "" , "display-stdout" , "to print stdout even if the test succeeds" ) ]
373
377
}
374
378
375
379
fn usage ( binary : & str ) {
@@ -481,6 +485,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
481
485
quiet : quiet,
482
486
test_threads : test_threads,
483
487
skip : matches. opt_strs ( "skip" ) ,
488
+ display_stdout : matches. opt_present ( "display-stdout" ) ,
484
489
} ;
485
490
486
491
Some ( Ok ( test_opts) )
@@ -521,7 +526,9 @@ struct ConsoleTestState<T> {
521
526
measured : usize ,
522
527
metrics : MetricMap ,
523
528
failures : Vec < ( TestDesc , Vec < u8 > ) > ,
529
+ not_failures : Vec < ( TestDesc , Vec < u8 > ) > ,
524
530
max_name_len : usize , // number of columns to fill when aligning names
531
+ display_stdout : bool ,
525
532
}
526
533
527
534
impl < T : Write > ConsoleTestState < T > {
@@ -547,7 +554,9 @@ impl<T: Write> ConsoleTestState<T> {
547
554
measured : 0 ,
548
555
metrics : MetricMap :: new ( ) ,
549
556
failures : Vec :: new ( ) ,
557
+ not_failures : Vec :: new ( ) ,
550
558
max_name_len : 0 ,
559
+ display_stdout : opts. display_stdout ,
551
560
} )
552
561
}
553
562
@@ -703,9 +712,38 @@ impl<T: Write> ConsoleTestState<T> {
703
712
Ok ( ( ) )
704
713
}
705
714
715
+ pub fn write_outputs ( & mut self ) -> io:: Result < ( ) > {
716
+ self . write_plain ( "\n successes:\n " ) ?;
717
+ let mut successes = Vec :: new ( ) ;
718
+ let mut stdouts = String :: new ( ) ;
719
+ for & ( ref f, ref stdout) in & self . not_failures {
720
+ successes. push ( f. name . to_string ( ) ) ;
721
+ if !stdout. is_empty ( ) {
722
+ stdouts. push_str ( & format ! ( "---- {} stdout ----\n \t " , f. name) ) ;
723
+ let output = String :: from_utf8_lossy ( stdout) ;
724
+ stdouts. push_str ( & output) ;
725
+ stdouts. push_str ( "\n " ) ;
726
+ }
727
+ }
728
+ if !stdouts. is_empty ( ) {
729
+ self . write_plain ( "\n " ) ?;
730
+ self . write_plain ( & stdouts) ?;
731
+ }
732
+
733
+ self . write_plain ( "\n successes:\n " ) ?;
734
+ successes. sort ( ) ;
735
+ for name in & successes {
736
+ self . write_plain ( & format ! ( " {}\n " , name) ) ?;
737
+ }
738
+ Ok ( ( ) )
739
+ }
740
+
706
741
pub fn write_run_finish ( & mut self ) -> io:: Result < bool > {
707
742
assert ! ( self . passed + self . failed + self . ignored + self . measured == self . total) ;
708
743
744
+ if self . display_stdout {
745
+ self . write_outputs ( ) ?;
746
+ }
709
747
let success = self . failed == 0 ;
710
748
if !success {
711
749
self . write_failures ( ) ?;
@@ -824,7 +862,10 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
824
862
st. write_log_result ( & test, & result) ?;
825
863
st. write_result ( & result) ?;
826
864
match result {
827
- TrOk => st. passed += 1 ,
865
+ TrOk => {
866
+ st. passed += 1 ;
867
+ st. not_failures . push ( ( test, stdout) ) ;
868
+ }
828
869
TrIgnored => st. ignored += 1 ,
829
870
TrMetrics ( mm) => {
830
871
let tname = test. name ;
@@ -901,6 +942,8 @@ fn should_sort_failures_before_printing_them() {
901
942
max_name_len : 10 ,
902
943
metrics : MetricMap :: new ( ) ,
903
944
failures : vec ! [ ( test_b, Vec :: new( ) ) , ( test_a, Vec :: new( ) ) ] ,
945
+ display_stdout : false ,
946
+ not_failures : Vec :: new ( ) ,
904
947
} ;
905
948
906
949
st. write_failures ( ) . unwrap ( ) ;
0 commit comments