diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 9effdb2c959d0..d12e86b7c1deb 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -933,6 +933,8 @@ impl Step for RustdocGUI { let mut command = Command::new(&nodejs); command .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js")) + .arg("--jobs") + .arg(&builder.jobs().to_string()) .arg("--doc-folder") .arg(out_dir.join("doc")) .arg("--tests-folder") diff --git a/src/tools/rustdoc-gui/tester.js b/src/tools/rustdoc-gui/tester.js index 4e77d27d399c2..46b1f68c79a8a 100644 --- a/src/tools/rustdoc-gui/tester.js +++ b/src/tools/rustdoc-gui/tester.js @@ -17,6 +17,11 @@ function showHelp() { console.log(" --no-headless : disable headless mode"); console.log(" --help : show this message then quit"); console.log(" --tests-folder [PATH] : location of the .GOML tests folder"); + console.log(" --jobs [NUMBER] : number of threads to run tests on"); +} + +function isNumeric(s) { + return /^\d+$/.test(s); } function parseOptions(args) { @@ -27,6 +32,7 @@ function parseOptions(args) { "debug": false, "show_text": false, "no_headless": false, + "jobs": -1, }; var correspondances = { "--doc-folder": "doc_folder", @@ -39,13 +45,21 @@ function parseOptions(args) { for (var i = 0; i < args.length; ++i) { if (args[i] === "--doc-folder" || args[i] === "--tests-folder" - || args[i] === "--file") { + || args[i] === "--file" + || args[i] === "--jobs") { i += 1; if (i >= args.length) { console.log("Missing argument after `" + args[i - 1] + "` option."); return null; } - if (args[i - 1] !== "--file") { + if (args[i - 1] === "--jobs") { + if (!isNumeric(args[i])) { + console.log( + "`--jobs` option expects a positive number, found `" + args[i] + "`"); + return null; + } + opts["jobs"] = parseInt(args[i]); + } else if (args[i - 1] !== "--file") { opts[correspondances[args[i - 1]]] = args[i]; } else { opts["files"].push(args[i]); @@ -153,7 +167,11 @@ async function main(argv) { files.sort(); console.log(`Running ${files.length} rustdoc-gui tests...`); - process.setMaxListeners(files.length + 1); + if (opts["jobs"] < 1) { + process.setMaxListeners(files.length + 1); + } else { + process.setMaxListeners(opts["jobs"]); + } let tests = []; let results = { successful: [],