@@ -76,7 +76,7 @@ pub mod test {
76
76
pub use { Bencher , TestName , TestResult , TestDesc , TestDescAndFn , TestOpts , TrFailed ,
77
77
TrFailedMsg , TrIgnored , TrOk , Metric , MetricMap , StaticTestFn , StaticTestName ,
78
78
DynTestName , DynTestFn , run_test, test_main, test_main_static, filter_tests,
79
- parse_opts, StaticBenchFn , ShouldPanic } ;
79
+ parse_opts, StaticBenchFn , ShouldPanic , Options } ;
80
80
}
81
81
82
82
pub mod stats;
@@ -252,14 +252,34 @@ impl Clone for MetricMap {
252
252
}
253
253
}
254
254
255
+ /// In case we want to add other options as well, just add them in this struct.
256
+ #[ derive( Copy , Clone , Debug ) ]
257
+ pub struct Options {
258
+ display_output : bool ,
259
+ }
260
+
261
+ impl Options {
262
+ pub fn new ( ) -> Options {
263
+ Options {
264
+ display_output : false ,
265
+ }
266
+ }
267
+
268
+ pub fn display_output ( mut self , display_output : bool ) -> Options {
269
+ self . display_output = display_output;
270
+ self
271
+ }
272
+ }
273
+
255
274
// The default console test runner. It accepts the command line
256
275
// arguments and a vector of test_descs.
257
- pub fn test_main ( args : & [ String ] , tests : Vec < TestDescAndFn > ) {
258
- let opts = match parse_opts ( args) {
276
+ pub fn test_main ( args : & [ String ] , tests : Vec < TestDescAndFn > , options : Options ) {
277
+ let mut opts = match parse_opts ( args) {
259
278
Some ( Ok ( o) ) => o,
260
279
Some ( Err ( msg) ) => panic ! ( "{:?}" , msg) ,
261
280
None => return ,
262
281
} ;
282
+ opts. options = options;
263
283
if opts. list {
264
284
if let Err ( e) = list_tests_console ( & opts, tests) {
265
285
panic ! ( "io error when listing tests: {:?}" , e) ;
@@ -301,7 +321,7 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
301
321
}
302
322
} )
303
323
. collect ( ) ;
304
- test_main ( & args, owned_tests)
324
+ test_main ( & args, owned_tests, Options :: new ( ) )
305
325
}
306
326
307
327
#[ derive( Copy , Clone , Debug ) ]
@@ -325,7 +345,7 @@ pub struct TestOpts {
325
345
pub quiet : bool ,
326
346
pub test_threads : Option < usize > ,
327
347
pub skip : Vec < String > ,
328
- pub display_stdout : bool ,
348
+ pub options : Options ,
329
349
}
330
350
331
351
impl TestOpts {
@@ -344,7 +364,7 @@ impl TestOpts {
344
364
quiet : false ,
345
365
test_threads : None ,
346
366
skip : vec ! [ ] ,
347
- display_stdout : false ,
367
+ options : Options :: new ( ) ,
348
368
}
349
369
}
350
370
}
@@ -372,8 +392,7 @@ fn optgroups() -> Vec<getopts::OptGroup> {
372
392
getopts:: optopt( "" , "color" , "Configure coloring of output:
373
393
auto = colorize if stdout is a tty and tests are run on serially (default);
374
394
always = always colorize output;
375
- never = never colorize output;" , "auto|always|never" ) ,
376
- getopts:: optflag( "" , "display-stdout" , "to print stdout even if the test succeeds" ) ]
395
+ never = never colorize output;" , "auto|always|never" ) ]
377
396
}
378
397
379
398
fn usage ( binary : & str ) {
@@ -485,7 +504,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
485
504
quiet : quiet,
486
505
test_threads : test_threads,
487
506
skip : matches. opt_strs ( "skip" ) ,
488
- display_stdout : matches . opt_present ( "display-stdout" ) ,
507
+ options : Options :: new ( ) ,
489
508
} ;
490
509
491
510
Some ( Ok ( test_opts) )
@@ -528,7 +547,7 @@ struct ConsoleTestState<T> {
528
547
failures : Vec < ( TestDesc , Vec < u8 > ) > ,
529
548
not_failures : Vec < ( TestDesc , Vec < u8 > ) > ,
530
549
max_name_len : usize , // number of columns to fill when aligning names
531
- display_stdout : bool ,
550
+ options : Options ,
532
551
}
533
552
534
553
impl < T : Write > ConsoleTestState < T > {
@@ -556,7 +575,7 @@ impl<T: Write> ConsoleTestState<T> {
556
575
failures : Vec :: new ( ) ,
557
576
not_failures : Vec :: new ( ) ,
558
577
max_name_len : 0 ,
559
- display_stdout : opts. display_stdout ,
578
+ options : opts. options ,
560
579
} )
561
580
}
562
581
@@ -741,7 +760,7 @@ impl<T: Write> ConsoleTestState<T> {
741
760
pub fn write_run_finish ( & mut self ) -> io:: Result < bool > {
742
761
assert ! ( self . passed + self . failed + self . ignored + self . measured == self . total) ;
743
762
744
- if self . display_stdout {
763
+ if self . options . display_output {
745
764
self . write_outputs ( ) ?;
746
765
}
747
766
let success = self . failed == 0 ;
@@ -942,7 +961,7 @@ fn should_sort_failures_before_printing_them() {
942
961
max_name_len : 10 ,
943
962
metrics : MetricMap :: new ( ) ,
944
963
failures : vec ! [ ( test_b, Vec :: new( ) ) , ( test_a, Vec :: new( ) ) ] ,
945
- display_stdout : false ,
964
+ options : Options :: new ( ) ,
946
965
not_failures : Vec :: new ( ) ,
947
966
} ;
948
967
0 commit comments