@@ -109,7 +109,7 @@ impl fmt::Display for TestName {
109109 }
110110}
111111
112- #[ derive( Clone , Copy ) ]
112+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
113113enum NamePadding {
114114 PadNone ,
115115 PadOnRight ,
@@ -301,6 +301,7 @@ pub struct TestOpts {
301301 pub logfile : Option < PathBuf > ,
302302 pub nocapture : bool ,
303303 pub color : ColorConfig ,
304+ pub quiet : bool ,
304305}
305306
306307impl TestOpts {
@@ -314,6 +315,7 @@ impl TestOpts {
314315 logfile : None ,
315316 nocapture : false ,
316317 color : AutoColor ,
318+ quiet : false ,
317319 }
318320 }
319321}
@@ -331,6 +333,7 @@ fn optgroups() -> Vec<getopts::OptGroup> {
331333 of stdout", "PATH" ) ,
332334 getopts:: optflag( "" , "nocapture" , "don't capture stdout/stderr of each \
333335 task, allow printing directly") ,
336+ getopts:: optflag( "q" , "quiet" , "Display one character per test instead of one line" ) ,
334337 getopts:: optopt( "" , "color" , "Configure coloring of output:
335338 auto = colorize if stdout is a tty and tests are run on serially (default);
336339 always = always colorize output;
@@ -388,6 +391,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
388391 } ;
389392
390393 let run_ignored = matches. opt_present ( "ignored" ) ;
394+ let quiet = matches. opt_present ( "quiet" ) ;
391395
392396 let logfile = matches. opt_str ( "logfile" ) ;
393397 let logfile = logfile. map ( |s| PathBuf :: from ( & s) ) ;
@@ -420,6 +424,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
420424 logfile : logfile,
421425 nocapture : nocapture,
422426 color : color,
427+ quiet : quiet,
423428 } ;
424429
425430 Some ( Ok ( test_opts) )
@@ -451,6 +456,7 @@ struct ConsoleTestState<T> {
451456 log_out : Option < File > ,
452457 out : OutputLocation < T > ,
453458 use_color : bool ,
459+ quiet : bool ,
454460 total : usize ,
455461 passed : usize ,
456462 failed : usize ,
@@ -476,6 +482,7 @@ impl<T: Write> ConsoleTestState<T> {
476482 out : out,
477483 log_out : log_out,
478484 use_color : use_color ( opts) ,
485+ quiet : opts. quiet ,
479486 total : 0 ,
480487 passed : 0 ,
481488 failed : 0 ,
@@ -488,15 +495,15 @@ impl<T: Write> ConsoleTestState<T> {
488495 }
489496
490497 pub fn write_ok ( & mut self ) -> io:: Result < ( ) > {
491- self . write_pretty ( "ok" , term:: color:: GREEN )
498+ self . write_short_result ( "ok" , ". ", term:: color:: GREEN )
492499 }
493500
494501 pub fn write_failed ( & mut self ) -> io:: Result < ( ) > {
495- self . write_pretty ( "FAILED" , term:: color:: RED )
502+ self . write_short_result ( "FAILED" , "F ", term:: color:: RED )
496503 }
497504
498505 pub fn write_ignored ( & mut self ) -> io:: Result < ( ) > {
499- self . write_pretty ( "ignored" , term:: color:: YELLOW )
506+ self . write_short_result ( "ignored" , "i ", term:: color:: YELLOW )
500507 }
501508
502509 pub fn write_metric ( & mut self ) -> io:: Result < ( ) > {
@@ -507,6 +514,16 @@ impl<T: Write> ConsoleTestState<T> {
507514 self . write_pretty ( "bench" , term:: color:: CYAN )
508515 }
509516
517+ pub fn write_short_result ( & mut self , verbose : & str , quiet : & str , color : term:: color:: Color )
518+ -> io:: Result < ( ) > {
519+ if self . quiet {
520+ self . write_pretty ( quiet, color)
521+ } else {
522+ try!( self . write_pretty ( verbose, color) ) ;
523+ self . write_plain ( "\n " )
524+ }
525+ }
526+
510527 pub fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
511528 match self . out {
512529 Pretty ( ref mut term) => {
@@ -550,28 +567,28 @@ impl<T: Write> ConsoleTestState<T> {
550567 }
551568
552569 pub fn write_test_start ( & mut self , test : & TestDesc , align : NamePadding ) -> io:: Result < ( ) > {
553- let name = test. padded_name ( self . max_name_len , align) ;
554- self . write_plain ( & format ! ( "test {} ... " , name) )
570+ if self . quiet && align != PadOnRight {
571+ Ok ( ( ) )
572+ } else {
573+ let name = test. padded_name ( self . max_name_len , align) ;
574+ self . write_plain ( & format ! ( "test {} ... " , name) )
575+ }
555576 }
556577
557578 pub fn write_result ( & mut self , result : & TestResult ) -> io:: Result < ( ) > {
558- try! ( match * result {
579+ match * result {
559580 TrOk => self . write_ok ( ) ,
560581 TrFailed => self . write_failed ( ) ,
561582 TrIgnored => self . write_ignored ( ) ,
562583 TrMetrics ( ref mm) => {
563584 try!( self . write_metric ( ) ) ;
564- self . write_plain ( & format ! ( ": {}" , mm. fmt_metrics( ) ) )
585+ self . write_plain ( & format ! ( ": {}\n " , mm. fmt_metrics( ) ) )
565586 }
566587 TrBench ( ref bs) => {
567588 try!( self . write_bench ( ) ) ;
568-
569- try!( self . write_plain ( & format ! ( ": {}" , fmt_bench_samples( bs) ) ) ) ;
570-
571- Ok ( ( ) )
589+ self . write_plain ( & format ! ( ": {}\n " , fmt_bench_samples( bs) ) )
572590 }
573- } ) ;
574- self . write_plain ( "\n " )
591+ }
575592 }
576593
577594 pub fn write_log ( & mut self , test : & TestDesc , result : & TestResult ) -> io:: Result < ( ) > {
@@ -629,9 +646,9 @@ impl<T: Write> ConsoleTestState<T> {
629646 try!( self . write_plain ( "\n test result: " ) ) ;
630647 if success {
631648 // There's no parallelism at this point so it's safe to use color
632- try!( self . write_ok ( ) ) ;
649+ try!( self . write_pretty ( "ok" , term :: color :: GREEN ) ) ;
633650 } else {
634- try!( self . write_failed ( ) ) ;
651+ try!( self . write_pretty ( "FAILED" , term :: color :: RED ) ) ;
635652 }
636653 let s = format ! ( ". {} passed; {} failed; {} ignored; {} measured\n \n " ,
637654 self . passed,
@@ -758,6 +775,7 @@ fn should_sort_failures_before_printing_them() {
758775 log_out : None ,
759776 out : Raw ( Vec :: new ( ) ) ,
760777 use_color : false ,
778+ quiet : false ,
761779 total : 0 ,
762780 passed : 0 ,
763781 failed : 0 ,
0 commit comments