33
33
#![ cfg_attr( not( stage0) , deny( warnings) ) ]
34
34
35
35
#![ cfg_attr( feature = "asm_black_box" , feature( asm) ) ]
36
- #![ feature( set_stdio) ]
36
+ #![ cfg_attr ( feature = "capture" , feature ( set_stdio) ) ]
37
37
38
38
extern crate getopts;
39
39
extern crate rustc_serialize;
@@ -329,10 +329,12 @@ fn options() -> getopts::Options {
329
329
. optflag ( "" , "bench" , "Run benchmarks instead of tests" )
330
330
. optflag ( "h" , "help" , "Display this message (longer with --help)" )
331
331
. optopt ( "" , "logfile" , "Write logs to the specified file instead \
332
- of stdout", "PATH" )
333
- . optflag ( "" , "nocapture" , "don't capture stdout/stderr of each \
334
- task, allow printing directly")
335
- . optopt ( "" , "color" , "Configure coloring of output:
332
+ of stdout", "PATH" ) ;
333
+ if cfg ! ( feature = "capture" ) {
334
+ opts. optflag ( "" , "nocapture" , "don't capture stdout/stderr of each \
335
+ task, allow printing directly") ;
336
+ }
337
+ opts. optopt ( "" , "color" , "Configure coloring of output:
336
338
auto = colorize if stdout is a tty and tests are run on serially (default);
337
339
always = always colorize output;
338
340
never = never colorize output;" , "auto|always|never" ) ;
@@ -348,11 +350,17 @@ tests whose names contain the filter are run.
348
350
349
351
By default, all tests are run in parallel. This can be altered with the
350
352
RUST_TEST_THREADS environment variable when running tests (set it to 1).
353
+ "# , usage = options( ) . usage( & message) ) ;
351
354
355
+ if cfg ! ( feature = "capture" ) {
356
+ println ! ( r#"
352
357
All tests have their standard output and standard error captured by default.
353
358
This can be overridden with the --nocapture flag or the RUST_TEST_NOCAPTURE=1
354
359
environment variable. Logging is not captured by default.
360
+ "# ) ;
361
+ }
355
362
363
+ println ! ( r#"
356
364
Test Attributes:
357
365
358
366
#[test] - Indicates a function is a test to be run. This function
@@ -366,8 +374,7 @@ Test Attributes:
366
374
#[ignore] - When applied to a function which is already attributed as a
367
375
test, then the test runner will ignore these tests during
368
376
normal test runs. Running with --ignored will run these
369
- tests."# ,
370
- usage = options( ) . usage( & message) ) ;
377
+ tests."# ) ;
371
378
}
372
379
373
380
// Parses command line arguments into test options
@@ -1067,16 +1074,6 @@ pub fn run_test(opts: &TestOpts,
1067
1074
monitor_ch : Sender < MonitorMsg > ,
1068
1075
nocapture : bool ,
1069
1076
mut testfn : Box < FnMut ( ) + Send > ) {
1070
- struct Sink ( Arc < Mutex < Vec < u8 > > > ) ;
1071
- impl Write for Sink {
1072
- fn write ( & mut self , data : & [ u8 ] ) -> io:: Result < usize > {
1073
- Write :: write ( & mut * self . 0 . lock ( ) . unwrap ( ) , data)
1074
- }
1075
- fn flush ( & mut self ) -> io:: Result < ( ) > {
1076
- Ok ( ( ) )
1077
- }
1078
- }
1079
-
1080
1077
thread:: spawn ( move || {
1081
1078
let data = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
1082
1079
let data2 = data. clone ( ) ;
@@ -1085,10 +1082,27 @@ pub fn run_test(opts: &TestOpts,
1085
1082
StaticTestName ( name) => name. to_owned ( ) ,
1086
1083
} ) ;
1087
1084
1085
+ #[ cfg( feature = "capture" ) ]
1086
+ fn capture ( data2 : Arc < Mutex < Vec < u8 > > > ) {
1087
+ struct Sink ( Arc < Mutex < Vec < u8 > > > ) ;
1088
+ impl Write for Sink {
1089
+ fn write ( & mut self , data : & [ u8 ] ) -> io:: Result < usize > {
1090
+ Write :: write ( & mut * self . 0 . lock ( ) . unwrap ( ) , data)
1091
+ }
1092
+ fn flush ( & mut self ) -> io:: Result < ( ) > {
1093
+ Ok ( ( ) )
1094
+ }
1095
+ }
1096
+
1097
+ io:: set_print ( Box :: new ( Sink ( data2. clone ( ) ) ) ) ;
1098
+ io:: set_panic ( Box :: new ( Sink ( data2) ) ) ;
1099
+ }
1100
+ #[ cfg( not( feature = "capture" ) ) ]
1101
+ fn capture ( _data2 : Arc < Mutex < Vec < u8 > > > ) { }
1102
+
1088
1103
let result_guard = cfg. spawn ( move || {
1089
1104
if !nocapture {
1090
- io:: set_print ( Box :: new ( Sink ( data2. clone ( ) ) ) ) ;
1091
- io:: set_panic ( Box :: new ( Sink ( data2) ) ) ;
1105
+ capture ( data2)
1092
1106
}
1093
1107
testfn ( )
1094
1108
} )
0 commit comments