@@ -109,7 +109,7 @@ impl fmt::Display for TestName {
109
109
}
110
110
}
111
111
112
- #[ derive( Clone , Copy ) ]
112
+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
113
113
enum NamePadding {
114
114
PadNone ,
115
115
PadOnRight ,
@@ -301,6 +301,7 @@ pub struct TestOpts {
301
301
pub logfile : Option < PathBuf > ,
302
302
pub nocapture : bool ,
303
303
pub color : ColorConfig ,
304
+ pub quiet : bool ,
304
305
}
305
306
306
307
impl TestOpts {
@@ -314,6 +315,7 @@ impl TestOpts {
314
315
logfile : None ,
315
316
nocapture : false ,
316
317
color : AutoColor ,
318
+ quiet : false ,
317
319
}
318
320
}
319
321
}
@@ -331,6 +333,7 @@ fn optgroups() -> Vec<getopts::OptGroup> {
331
333
of stdout", "PATH" ) ,
332
334
getopts:: optflag( "" , "nocapture" , "don't capture stdout/stderr of each \
333
335
task, allow printing directly") ,
336
+ getopts:: optflag( "q" , "quiet" , "Display one character per test instead of one line" ) ,
334
337
getopts:: optopt( "" , "color" , "Configure coloring of output:
335
338
auto = colorize if stdout is a tty and tests are run on serially (default);
336
339
always = always colorize output;
@@ -388,6 +391,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
388
391
} ;
389
392
390
393
let run_ignored = matches. opt_present ( "ignored" ) ;
394
+ let quiet = matches. opt_present ( "quiet" ) ;
391
395
392
396
let logfile = matches. opt_str ( "logfile" ) ;
393
397
let logfile = logfile. map ( |s| PathBuf :: from ( & s) ) ;
@@ -420,6 +424,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
420
424
logfile : logfile,
421
425
nocapture : nocapture,
422
426
color : color,
427
+ quiet : quiet,
423
428
} ;
424
429
425
430
Some ( Ok ( test_opts) )
@@ -451,6 +456,7 @@ struct ConsoleTestState<T> {
451
456
log_out : Option < File > ,
452
457
out : OutputLocation < T > ,
453
458
use_color : bool ,
459
+ quiet : bool ,
454
460
total : usize ,
455
461
passed : usize ,
456
462
failed : usize ,
@@ -476,6 +482,7 @@ impl<T: Write> ConsoleTestState<T> {
476
482
out : out,
477
483
log_out : log_out,
478
484
use_color : use_color ( opts) ,
485
+ quiet : opts. quiet ,
479
486
total : 0 ,
480
487
passed : 0 ,
481
488
failed : 0 ,
@@ -488,15 +495,15 @@ impl<T: Write> ConsoleTestState<T> {
488
495
}
489
496
490
497
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 )
492
499
}
493
500
494
501
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 )
496
503
}
497
504
498
505
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 )
500
507
}
501
508
502
509
pub fn write_metric ( & mut self ) -> io:: Result < ( ) > {
@@ -507,6 +514,16 @@ impl<T: Write> ConsoleTestState<T> {
507
514
self . write_pretty ( "bench" , term:: color:: CYAN )
508
515
}
509
516
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
+
510
527
pub fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
511
528
match self . out {
512
529
Pretty ( ref mut term) => {
@@ -550,28 +567,28 @@ impl<T: Write> ConsoleTestState<T> {
550
567
}
551
568
552
569
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
+ }
555
576
}
556
577
557
578
pub fn write_result ( & mut self , result : & TestResult ) -> io:: Result < ( ) > {
558
- try! ( match * result {
579
+ match * result {
559
580
TrOk => self . write_ok ( ) ,
560
581
TrFailed => self . write_failed ( ) ,
561
582
TrIgnored => self . write_ignored ( ) ,
562
583
TrMetrics ( ref mm) => {
563
584
try!( self . write_metric ( ) ) ;
564
- self . write_plain ( & format ! ( ": {}" , mm. fmt_metrics( ) ) )
585
+ self . write_plain ( & format ! ( ": {}\n " , mm. fmt_metrics( ) ) )
565
586
}
566
587
TrBench ( ref bs) => {
567
588
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) ) )
572
590
}
573
- } ) ;
574
- self . write_plain ( "\n " )
591
+ }
575
592
}
576
593
577
594
pub fn write_log ( & mut self , test : & TestDesc , result : & TestResult ) -> io:: Result < ( ) > {
@@ -629,9 +646,9 @@ impl<T: Write> ConsoleTestState<T> {
629
646
try!( self . write_plain ( "\n test result: " ) ) ;
630
647
if success {
631
648
// 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 ) ) ;
633
650
} else {
634
- try!( self . write_failed ( ) ) ;
651
+ try!( self . write_pretty ( "FAILED" , term :: color :: RED ) ) ;
635
652
}
636
653
let s = format ! ( ". {} passed; {} failed; {} ignored; {} measured\n \n " ,
637
654
self . passed,
@@ -758,6 +775,7 @@ fn should_sort_failures_before_printing_them() {
758
775
log_out : None ,
759
776
out : Raw ( Vec :: new ( ) ) ,
760
777
use_color : false ,
778
+ quiet : false ,
761
779
total : 0 ,
762
780
passed : 0 ,
763
781
failed : 0 ,
0 commit comments