@@ -304,13 +304,14 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
304304 test_main ( & args, owned_tests)
305305}
306306
307- #[ derive( Copy , Clone ) ]
307+ #[ derive( Copy , Clone , Debug ) ]
308308pub enum ColorConfig {
309309 AutoColor ,
310310 AlwaysColor ,
311311 NeverColor ,
312312}
313313
314+ #[ derive( Debug ) ]
314315pub struct TestOpts {
315316 pub list : bool ,
316317 pub filter : Option < String > ,
@@ -324,6 +325,7 @@ pub struct TestOpts {
324325 pub quiet : bool ,
325326 pub test_threads : Option < usize > ,
326327 pub skip : Vec < String > ,
328+ pub display_stdout : bool ,
327329}
328330
329331impl TestOpts {
@@ -342,6 +344,7 @@ impl TestOpts {
342344 quiet : false ,
343345 test_threads : None ,
344346 skip : vec ! [ ] ,
347+ display_stdout : false ,
345348 }
346349 }
347350}
@@ -369,7 +372,8 @@ fn optgroups() -> Vec<getopts::OptGroup> {
369372 getopts:: optopt( "" , "color" , "Configure coloring of output:
370373 auto = colorize if stdout is a tty and tests are run on serially (default);
371374 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" ) ]
373377}
374378
375379fn usage ( binary : & str ) {
@@ -481,6 +485,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
481485 quiet : quiet,
482486 test_threads : test_threads,
483487 skip : matches. opt_strs ( "skip" ) ,
488+ display_stdout : matches. opt_present ( "display-stdout" ) ,
484489 } ;
485490
486491 Some ( Ok ( test_opts) )
@@ -521,7 +526,9 @@ struct ConsoleTestState<T> {
521526 measured : usize ,
522527 metrics : MetricMap ,
523528 failures : Vec < ( TestDesc , Vec < u8 > ) > ,
529+ not_failures : Vec < ( TestDesc , Vec < u8 > ) > ,
524530 max_name_len : usize , // number of columns to fill when aligning names
531+ display_stdout : bool ,
525532}
526533
527534impl < T : Write > ConsoleTestState < T > {
@@ -547,7 +554,9 @@ impl<T: Write> ConsoleTestState<T> {
547554 measured : 0 ,
548555 metrics : MetricMap :: new ( ) ,
549556 failures : Vec :: new ( ) ,
557+ not_failures : Vec :: new ( ) ,
550558 max_name_len : 0 ,
559+ display_stdout : opts. display_stdout ,
551560 } )
552561 }
553562
@@ -703,9 +712,38 @@ impl<T: Write> ConsoleTestState<T> {
703712 Ok ( ( ) )
704713 }
705714
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+
706741 pub fn write_run_finish ( & mut self ) -> io:: Result < bool > {
707742 assert ! ( self . passed + self . failed + self . ignored + self . measured == self . total) ;
708743
744+ if self . display_stdout {
745+ self . write_outputs ( ) ?;
746+ }
709747 let success = self . failed == 0 ;
710748 if !success {
711749 self . write_failures ( ) ?;
@@ -824,7 +862,10 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
824862 st. write_log_result ( & test, & result) ?;
825863 st. write_result ( & result) ?;
826864 match result {
827- TrOk => st. passed += 1 ,
865+ TrOk => {
866+ st. passed += 1 ;
867+ st. not_failures . push ( ( test, stdout) ) ;
868+ }
828869 TrIgnored => st. ignored += 1 ,
829870 TrMetrics ( mm) => {
830871 let tname = test. name ;
@@ -901,6 +942,8 @@ fn should_sort_failures_before_printing_them() {
901942 max_name_len : 10 ,
902943 metrics : MetricMap :: new ( ) ,
903944 failures : vec ! [ ( test_b, Vec :: new( ) ) , ( test_a, Vec :: new( ) ) ] ,
945+ display_stdout : false ,
946+ not_failures : Vec :: new ( ) ,
904947 } ;
905948
906949 st. write_failures ( ) . unwrap ( ) ;
0 commit comments