@@ -300,6 +300,7 @@ pub struct TestOpts {
300300 pub nocapture : bool ,
301301 pub color : ColorConfig ,
302302 pub quiet : bool ,
303+ pub test_threads : Option < usize > ,
303304}
304305
305306impl TestOpts {
@@ -314,6 +315,7 @@ impl TestOpts {
314315 nocapture : false ,
315316 color : AutoColor ,
316317 quiet : false ,
318+ test_threads : None ,
317319 }
318320 }
319321}
@@ -331,6 +333,8 @@ fn optgroups() -> Vec<getopts::OptGroup> {
331333 of stdout", "PATH" ) ,
332334 getopts:: optflag( "" , "nocapture" , "don't capture stdout/stderr of each \
333335 task, allow printing directly") ,
336+ getopts:: optopt( "" , "test-threads" , "Number of threads used for running tests \
337+ in parallel", "n_threads" ) ,
334338 getopts:: optflag( "q" , "quiet" , "Display one character per test instead of one line" ) ,
335339 getopts:: optopt( "" , "color" , "Configure coloring of output:
336340 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
346350tests whose names contain the filter are run.
347351
348352By 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).
350355
351356All tests have their standard output and standard error captured by default.
352357This can be overridden with the --nocapture flag or setting RUST_TEST_NOCAPTURE
@@ -405,6 +410,18 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
405410 } ;
406411 }
407412
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+
408425 let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & * * s) {
409426 Some ( "auto" ) | None => AutoColor ,
410427 Some ( "always" ) => AlwaysColor ,
@@ -426,6 +443,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
426443 nocapture : nocapture,
427444 color : color,
428445 quiet : quiet,
446+ test_threads : test_threads,
429447 } ;
430448
431449 Some ( Ok ( test_opts) )
@@ -857,9 +875,10 @@ fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut callback: F) ->
857875 }
858876 } ) ;
859877
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+ } ;
863882
864883 let mut remaining = filtered_tests;
865884 remaining. reverse ( ) ;
0 commit comments