@@ -76,7 +76,7 @@ pub mod test {
7676 pub use { Bencher , TestName , TestResult , TestDesc , TestDescAndFn , TestOpts , TrFailed ,
7777 TrFailedMsg , TrIgnored , TrOk , Metric , MetricMap , StaticTestFn , StaticTestName ,
7878 DynTestName , DynTestFn , run_test, test_main, test_main_static, filter_tests,
79- parse_opts, StaticBenchFn , ShouldPanic } ;
79+ parse_opts, StaticBenchFn , ShouldPanic , Options } ;
8080}
8181
8282pub mod stats;
@@ -252,14 +252,34 @@ impl Clone for MetricMap {
252252 }
253253}
254254
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+
255274// The default console test runner. It accepts the command line
256275// 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) {
259278 Some ( Ok ( o) ) => o,
260279 Some ( Err ( msg) ) => panic ! ( "{:?}" , msg) ,
261280 None => return ,
262281 } ;
282+ opts. options = options;
263283 if opts. list {
264284 if let Err ( e) = list_tests_console ( & opts, tests) {
265285 panic ! ( "io error when listing tests: {:?}" , e) ;
@@ -301,7 +321,7 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
301321 }
302322 } )
303323 . collect ( ) ;
304- test_main ( & args, owned_tests)
324+ test_main ( & args, owned_tests, Options :: new ( ) )
305325}
306326
307327#[ derive( Copy , Clone , Debug ) ]
@@ -325,7 +345,7 @@ pub struct TestOpts {
325345 pub quiet : bool ,
326346 pub test_threads : Option < usize > ,
327347 pub skip : Vec < String > ,
328- pub display_stdout : bool ,
348+ pub options : Options ,
329349}
330350
331351impl TestOpts {
@@ -344,7 +364,7 @@ impl TestOpts {
344364 quiet : false ,
345365 test_threads : None ,
346366 skip : vec ! [ ] ,
347- display_stdout : false ,
367+ options : Options :: new ( ) ,
348368 }
349369 }
350370}
@@ -372,8 +392,7 @@ fn optgroups() -> Vec<getopts::OptGroup> {
372392 getopts:: optopt( "" , "color" , "Configure coloring of output:
373393 auto = colorize if stdout is a tty and tests are run on serially (default);
374394 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" ) ]
377396}
378397
379398fn usage ( binary : & str ) {
@@ -485,7 +504,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
485504 quiet : quiet,
486505 test_threads : test_threads,
487506 skip : matches. opt_strs ( "skip" ) ,
488- display_stdout : matches . opt_present ( "display-stdout" ) ,
507+ options : Options :: new ( ) ,
489508 } ;
490509
491510 Some ( Ok ( test_opts) )
@@ -528,7 +547,7 @@ struct ConsoleTestState<T> {
528547 failures : Vec < ( TestDesc , Vec < u8 > ) > ,
529548 not_failures : Vec < ( TestDesc , Vec < u8 > ) > ,
530549 max_name_len : usize , // number of columns to fill when aligning names
531- display_stdout : bool ,
550+ options : Options ,
532551}
533552
534553impl < T : Write > ConsoleTestState < T > {
@@ -556,7 +575,7 @@ impl<T: Write> ConsoleTestState<T> {
556575 failures : Vec :: new ( ) ,
557576 not_failures : Vec :: new ( ) ,
558577 max_name_len : 0 ,
559- display_stdout : opts. display_stdout ,
578+ options : opts. options ,
560579 } )
561580 }
562581
@@ -741,7 +760,7 @@ impl<T: Write> ConsoleTestState<T> {
741760 pub fn write_run_finish ( & mut self ) -> io:: Result < bool > {
742761 assert ! ( self . passed + self . failed + self . ignored + self . measured == self . total) ;
743762
744- if self . display_stdout {
763+ if self . options . display_output {
745764 self . write_outputs ( ) ?;
746765 }
747766 let success = self . failed == 0 ;
@@ -942,7 +961,7 @@ fn should_sort_failures_before_printing_them() {
942961 max_name_len : 10 ,
943962 metrics : MetricMap :: new ( ) ,
944963 failures : vec ! [ ( test_b, Vec :: new( ) ) , ( test_a, Vec :: new( ) ) ] ,
945- display_stdout : false ,
964+ options : Options :: new ( ) ,
946965 not_failures : Vec :: new ( ) ,
947966 } ;
948967
0 commit comments