@@ -303,6 +303,7 @@ pub struct TestOpts {
303
303
pub nocapture : bool ,
304
304
pub color : ColorConfig ,
305
305
pub quiet : bool ,
306
+ pub test_threads : Option < usize > ,
306
307
}
307
308
308
309
impl TestOpts {
@@ -317,6 +318,7 @@ impl TestOpts {
317
318
nocapture : false ,
318
319
color : AutoColor ,
319
320
quiet : false ,
321
+ test_threads : None ,
320
322
}
321
323
}
322
324
}
@@ -334,6 +336,8 @@ fn optgroups() -> Vec<getopts::OptGroup> {
334
336
of stdout", "PATH" ) ,
335
337
getopts:: optflag( "" , "nocapture" , "don't capture stdout/stderr of each \
336
338
task, allow printing directly") ,
339
+ getopts:: optopt( "" , "test-threads" , "Number of threads used for running tests \
340
+ in parallel", "n_threads" ) ,
337
341
getopts:: optflag( "q" , "quiet" , "Display one character per test instead of one line" ) ,
338
342
getopts:: optopt( "" , "color" , "Configure coloring of output:
339
343
auto = colorize if stdout is a tty and tests are run on serially (default);
@@ -349,7 +353,8 @@ The FILTER string is tested against the name of all tests, and only those
349
353
tests whose names contain the filter are run.
350
354
351
355
By default, all tests are run in parallel. This can be altered with the
352
- RUST_TEST_THREADS environment variable when running tests (set it to 1).
356
+ --test-threads flag or the RUST_TEST_THREADS environment variable when running
357
+ tests (set it to 1).
353
358
354
359
All tests have their standard output and standard error captured by default.
355
360
This can be overridden with the --nocapture flag or setting RUST_TEST_NOCAPTURE
@@ -408,6 +413,18 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
408
413
} ;
409
414
}
410
415
416
+ let test_threads = match matches. opt_str ( "test-threads" ) {
417
+ Some ( n_str) =>
418
+ match n_str. parse :: < usize > ( ) {
419
+ Ok ( n) => Some ( n) ,
420
+ Err ( e) =>
421
+ return Some ( Err ( format ! ( "argument for --test-threads must be a number > 0 \
422
+ (error: {})", e) ) )
423
+ } ,
424
+ None =>
425
+ None ,
426
+ } ;
427
+
411
428
let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & * * s) {
412
429
Some ( "auto" ) | None => AutoColor ,
413
430
Some ( "always" ) => AlwaysColor ,
@@ -429,6 +446,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
429
446
nocapture : nocapture,
430
447
color : color,
431
448
quiet : quiet,
449
+ test_threads : test_threads,
432
450
} ;
433
451
434
452
Some ( Ok ( test_opts) )
@@ -871,9 +889,10 @@ fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut callback: F) ->
871
889
}
872
890
} ) ;
873
891
874
- // It's tempting to just spawn all the tests at once, but since we have
875
- // many tests that run in other processes we would be making a big mess.
876
- let concurrency = get_concurrency ( ) ;
892
+ let concurrency = match opts. test_threads {
893
+ Some ( n) => n,
894
+ None => get_concurrency ( ) ,
895
+ } ;
877
896
878
897
let mut remaining = filtered_tests;
879
898
remaining. reverse ( ) ;
0 commit comments