@@ -102,7 +102,7 @@ impl fmt::Display for TestName {
102
102
}
103
103
}
104
104
105
- #[ derive( Clone , Copy ) ]
105
+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
106
106
enum NamePadding {
107
107
PadNone ,
108
108
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 verbose : 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
+ verbose : false ,
317
319
}
318
320
}
319
321
}
@@ -337,7 +339,8 @@ fn options() -> getopts::Options {
337
339
opts. optopt ( "" , "color" , "Configure coloring of output:
338
340
auto = colorize if stdout is a tty and tests are run on serially (default);
339
341
always = always colorize output;
340
- never = never colorize output;" , "auto|always|never" ) ;
342
+ never = never colorize output;" , "auto|always|never" )
343
+ . optflag ( "v" , "verbose" , "Display the name of each test when it starts" ) ;
341
344
opts
342
345
}
343
346
@@ -397,6 +400,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
397
400
} ;
398
401
399
402
let run_ignored = matches. opt_present ( "ignored" ) ;
403
+ let verbose = matches. opt_present ( "verbose" ) ;
400
404
401
405
let logfile = matches. opt_str ( "logfile" ) ;
402
406
let logfile = logfile. map ( |s| PathBuf :: from ( & s) ) ;
@@ -430,6 +434,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
430
434
logfile : logfile,
431
435
nocapture : nocapture,
432
436
color : color,
437
+ verbose : verbose,
433
438
} ;
434
439
435
440
Some ( Ok ( test_opts) )
@@ -461,6 +466,7 @@ struct ConsoleTestState<T> {
461
466
log_out : Option < File > ,
462
467
out : OutputLocation < T > ,
463
468
use_color : bool ,
469
+ verbose : bool ,
464
470
total : usize ,
465
471
passed : usize ,
466
472
failed : usize ,
@@ -486,6 +492,7 @@ impl<T: Write> ConsoleTestState<T> {
486
492
out : out,
487
493
log_out : log_out,
488
494
use_color : use_color ( opts) ,
495
+ verbose : opts. verbose ,
489
496
total : 0 ,
490
497
passed : 0 ,
491
498
failed : 0 ,
@@ -498,15 +505,15 @@ impl<T: Write> ConsoleTestState<T> {
498
505
}
499
506
500
507
pub fn write_ok ( & mut self ) -> io:: Result < ( ) > {
501
- self . write_pretty ( "ok" , term:: color:: GREEN )
508
+ self . write_short_result ( "ok" , ". ", term:: color:: GREEN )
502
509
}
503
510
504
511
pub fn write_failed ( & mut self ) -> io:: Result < ( ) > {
505
- self . write_pretty ( "FAILED" , term:: color:: RED )
512
+ self . write_short_result ( "FAILED" , "F ", term:: color:: RED )
506
513
}
507
514
508
515
pub fn write_ignored ( & mut self ) -> io:: Result < ( ) > {
509
- self . write_pretty ( "ignored" , term:: color:: YELLOW )
516
+ self . write_short_result ( "ignored" , "i ", term:: color:: YELLOW )
510
517
}
511
518
512
519
pub fn write_metric ( & mut self ) -> io:: Result < ( ) > {
@@ -517,6 +524,16 @@ impl<T: Write> ConsoleTestState<T> {
517
524
self . write_pretty ( "bench" , term:: color:: CYAN )
518
525
}
519
526
527
+ pub fn write_short_result ( & mut self , verbose : & str , quiet : & str , color : term:: color:: Color )
528
+ -> io:: Result < ( ) > {
529
+ if self . verbose {
530
+ try!( self . write_pretty ( verbose, color) ) ;
531
+ self . write_plain ( "\n " )
532
+ } else {
533
+ self . write_pretty ( quiet, color)
534
+ }
535
+ }
536
+
520
537
pub fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
521
538
match self . out {
522
539
Pretty ( ref mut term) => {
@@ -560,28 +577,28 @@ impl<T: Write> ConsoleTestState<T> {
560
577
}
561
578
562
579
pub fn write_test_start ( & mut self , test : & TestDesc , align : NamePadding ) -> io:: Result < ( ) > {
563
- let name = test. padded_name ( self . max_name_len , align) ;
564
- self . write_plain ( & format ! ( "test {} ... " , name) )
580
+ if self . verbose || align == PadOnRight {
581
+ let name = test. padded_name ( self . max_name_len , align) ;
582
+ self . write_plain ( & format ! ( "test {} ... " , name) )
583
+ } else {
584
+ Ok ( ( ) )
585
+ }
565
586
}
566
587
567
588
pub fn write_result ( & mut self , result : & TestResult ) -> io:: Result < ( ) > {
568
- try! ( match * result {
589
+ match * result {
569
590
TrOk => self . write_ok ( ) ,
570
591
TrFailed => self . write_failed ( ) ,
571
592
TrIgnored => self . write_ignored ( ) ,
572
593
TrMetrics ( ref mm) => {
573
594
try!( self . write_metric ( ) ) ;
574
- self . write_plain ( & format ! ( ": {}" , mm. fmt_metrics( ) ) )
595
+ self . write_plain ( & format ! ( ": {}\n " , mm. fmt_metrics( ) ) )
575
596
}
576
597
TrBench ( ref bs) => {
577
598
try!( self . write_bench ( ) ) ;
578
-
579
- try!( self . write_plain ( & format ! ( ": {}" , fmt_bench_samples( bs) ) ) ) ;
580
-
581
- Ok ( ( ) )
599
+ self . write_plain ( & format ! ( ": {}\n " , fmt_bench_samples( bs) ) )
582
600
}
583
- } ) ;
584
- self . write_plain ( "\n " )
601
+ }
585
602
}
586
603
587
604
pub fn write_log ( & mut self , test : & TestDesc , result : & TestResult ) -> io:: Result < ( ) > {
@@ -639,9 +656,9 @@ impl<T: Write> ConsoleTestState<T> {
639
656
try!( self . write_plain ( "\n test result: " ) ) ;
640
657
if success {
641
658
// There's no parallelism at this point so it's safe to use color
642
- try!( self . write_ok ( ) ) ;
659
+ try!( self . write_pretty ( "ok" , term :: color :: GREEN ) ) ;
643
660
} else {
644
- try!( self . write_failed ( ) ) ;
661
+ try!( self . write_pretty ( "FAILED" , term :: color :: RED ) ) ;
645
662
}
646
663
let s = format ! ( ". {} passed; {} failed; {} ignored; {} measured\n \n " ,
647
664
self . passed,
0 commit comments