@@ -300,6 +300,7 @@ pub struct TestOpts {
300
300
pub nocapture : bool ,
301
301
pub color : ColorConfig ,
302
302
pub quiet : bool ,
303
+ pub test_threads : Option < usize > ,
303
304
}
304
305
305
306
impl TestOpts {
@@ -314,6 +315,7 @@ impl TestOpts {
314
315
nocapture : false ,
315
316
color : AutoColor ,
316
317
quiet : false ,
318
+ test_threads : None ,
317
319
}
318
320
}
319
321
}
@@ -331,6 +333,8 @@ fn optgroups() -> Vec<getopts::OptGroup> {
331
333
of stdout", "PATH" ) ,
332
334
getopts:: optflag( "" , "nocapture" , "don't capture stdout/stderr of each \
333
335
task, allow printing directly") ,
336
+ getopts:: optopt( "" , "test-threads" , "Number of threads used for running tests \
337
+ in parallel", "n_threads" ) ,
334
338
getopts:: optflag( "q" , "quiet" , "Display one character per test instead of one line" ) ,
335
339
getopts:: optopt( "" , "color" , "Configure coloring of output:
336
340
auto = colorize if stdout is a tty and tests are run on serially (default);
@@ -346,7 +350,8 @@ The FILTER string is tested against the name of all tests, and only those
346
350
tests whose names contain the filter are run.
347
351
348
352
By default, all tests are run in parallel. This can be altered with the
349
- RUST_TEST_THREADS environment variable when running tests (set it to 1).
353
+ --test-threads flag or the RUST_TEST_THREADS environment variable when running
354
+ tests (set it to 1).
350
355
351
356
All tests have their standard output and standard error captured by default.
352
357
This can be overridden with the --nocapture flag or setting RUST_TEST_NOCAPTURE
@@ -405,6 +410,18 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
405
410
} ;
406
411
}
407
412
413
+ let test_threads = match matches. opt_str ( "test-threads" ) {
414
+ Some ( n_str) =>
415
+ match n_str. parse :: < usize > ( ) {
416
+ Ok ( n) => Some ( n) ,
417
+ Err ( e) =>
418
+ return Some ( Err ( format ! ( "argument for --test-threads must be a number > 0 \
419
+ (error: {})", e) ) )
420
+ } ,
421
+ None =>
422
+ None ,
423
+ } ;
424
+
408
425
let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & * * s) {
409
426
Some ( "auto" ) | None => AutoColor ,
410
427
Some ( "always" ) => AlwaysColor ,
@@ -426,6 +443,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
426
443
nocapture : nocapture,
427
444
color : color,
428
445
quiet : quiet,
446
+ test_threads : test_threads,
429
447
} ;
430
448
431
449
Some ( Ok ( test_opts) )
@@ -857,9 +875,10 @@ fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut callback: F) ->
857
875
}
858
876
} ) ;
859
877
860
- // It's tempting to just spawn all the tests at once, but since we have
861
- // many tests that run in other processes we would be making a big mess.
862
- let concurrency = get_concurrency ( ) ;
878
+ let concurrency = match opts. test_threads {
879
+ Some ( n) => n,
880
+ None => get_concurrency ( ) ,
881
+ } ;
863
882
864
883
let mut remaining = filtered_tests;
865
884
remaining. reverse ( ) ;
0 commit comments