2021-02-21 13:21:04 +00:00
|
|
|
// This package needs to be install:
|
|
|
|
//
|
|
|
|
// ```
|
|
|
|
// npm install browser-ui-test
|
|
|
|
// ```
|
2021-05-07 14:51:00 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2021-02-21 13:21:04 +00:00
|
|
|
const {Options, runTest} = require('browser-ui-test');
|
|
|
|
|
|
|
|
function showHelp() {
|
|
|
|
console.log("rustdoc-js options:");
|
|
|
|
console.log(" --doc-folder [PATH] : location of the generated doc folder");
|
2021-06-14 14:40:10 +00:00
|
|
|
console.log(" --file [PATH] : file to run (can be repeated)");
|
2021-06-14 15:55:25 +00:00
|
|
|
console.log(" --debug : show extra information about script run");
|
|
|
|
console.log(" --show-text : render font in pages");
|
|
|
|
console.log(" --no-headless : disable headless mode");
|
2021-02-21 13:21:04 +00:00
|
|
|
console.log(" --help : show this message then quit");
|
2021-05-07 14:51:00 +00:00
|
|
|
console.log(" --tests-folder [PATH] : location of the .GOML tests folder");
|
2021-02-21 13:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseOptions(args) {
|
|
|
|
var opts = {
|
|
|
|
"doc_folder": "",
|
2021-05-07 14:51:00 +00:00
|
|
|
"tests_folder": "",
|
2021-06-14 14:40:10 +00:00
|
|
|
"files": [],
|
2021-06-14 15:55:25 +00:00
|
|
|
"debug": false,
|
|
|
|
"show_text": false,
|
|
|
|
"no_headless": false,
|
2021-02-21 13:21:04 +00:00
|
|
|
};
|
|
|
|
var correspondances = {
|
|
|
|
"--doc-folder": "doc_folder",
|
2021-05-07 14:51:00 +00:00
|
|
|
"--tests-folder": "tests_folder",
|
2021-06-14 15:55:25 +00:00
|
|
|
"--debug": "debug",
|
|
|
|
"--show-text": "show_text",
|
|
|
|
"--no-headless": "no_headless",
|
2021-02-21 13:21:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < args.length; ++i) {
|
|
|
|
if (args[i] === "--doc-folder"
|
2021-06-14 14:40:10 +00:00
|
|
|
|| args[i] === "--tests-folder"
|
|
|
|
|| args[i] === "--file") {
|
2021-02-21 13:21:04 +00:00
|
|
|
i += 1;
|
|
|
|
if (i >= args.length) {
|
|
|
|
console.log("Missing argument after `" + args[i - 1] + "` option.");
|
|
|
|
return null;
|
|
|
|
}
|
2021-06-14 14:40:10 +00:00
|
|
|
if (args[i - 1] !== "--file") {
|
|
|
|
opts[correspondances[args[i - 1]]] = args[i];
|
|
|
|
} else {
|
|
|
|
opts["files"].push(args[i]);
|
|
|
|
}
|
2021-02-21 13:21:04 +00:00
|
|
|
} else if (args[i] === "--help") {
|
|
|
|
showHelp();
|
|
|
|
process.exit(0);
|
2021-06-14 15:55:25 +00:00
|
|
|
} else if (correspondances[args[i]]) {
|
|
|
|
opts[correspondances[args[i]]] = true;
|
2021-02-21 13:21:04 +00:00
|
|
|
} else {
|
|
|
|
console.log("Unknown option `" + args[i] + "`.");
|
|
|
|
console.log("Use `--help` to see the list of options");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2021-05-07 14:51:00 +00:00
|
|
|
if (opts["tests_folder"].length < 1) {
|
|
|
|
console.log("Missing `--tests-folder` option.");
|
2021-02-21 13:21:04 +00:00
|
|
|
} else if (opts["doc_folder"].length < 1) {
|
|
|
|
console.log("Missing `--doc-folder` option.");
|
|
|
|
} else {
|
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-25 07:59:04 +00:00
|
|
|
function print_test_successful() {
|
|
|
|
process.stdout.write(".");
|
|
|
|
}
|
2021-06-28 23:01:40 +00:00
|
|
|
|
2021-06-25 07:59:04 +00:00
|
|
|
function print_test_erroneous() {
|
2021-07-01 14:46:14 +00:00
|
|
|
process.stderr.write("F");
|
2021-06-25 07:59:04 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 14:51:00 +00:00
|
|
|
async function main(argv) {
|
|
|
|
let opts = parseOptions(argv.slice(2));
|
2021-02-21 13:21:04 +00:00
|
|
|
if (opts === null) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2021-06-28 23:41:39 +00:00
|
|
|
// Print successful tests too
|
2021-06-28 23:01:40 +00:00
|
|
|
let debug = false;
|
2021-06-28 23:41:39 +00:00
|
|
|
// Run tests in sequentially
|
|
|
|
let no_headless = false;
|
2021-02-21 13:21:04 +00:00
|
|
|
const options = new Options();
|
|
|
|
try {
|
|
|
|
// This is more convenient that setting fields one by one.
|
2021-06-14 15:55:25 +00:00
|
|
|
let args = [
|
2021-05-07 14:51:00 +00:00
|
|
|
"--no-screenshot",
|
2021-02-21 13:21:04 +00:00
|
|
|
"--variable", "DOC_PATH", opts["doc_folder"],
|
2021-06-14 15:55:25 +00:00
|
|
|
];
|
|
|
|
if (opts["debug"]) {
|
2021-06-28 23:01:40 +00:00
|
|
|
debug = true;
|
2021-06-14 15:55:25 +00:00
|
|
|
args.push("--debug");
|
|
|
|
}
|
|
|
|
if (opts["show_text"]) {
|
|
|
|
args.push("--show-text");
|
|
|
|
}
|
|
|
|
if (opts["no_headless"]) {
|
|
|
|
args.push("--no-headless");
|
2021-06-28 23:41:39 +00:00
|
|
|
no_headless = true;
|
2021-06-14 15:55:25 +00:00
|
|
|
}
|
|
|
|
options.parseArguments(args);
|
2021-02-21 13:21:04 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.error(`invalid argument: ${error}`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2021-05-07 14:51:00 +00:00
|
|
|
let failed = false;
|
2021-06-14 14:40:10 +00:00
|
|
|
let files;
|
|
|
|
if (opts["files"].length === 0) {
|
2021-06-28 23:01:40 +00:00
|
|
|
files = fs.readdirSync(opts["tests_folder"]);
|
2021-06-14 14:40:10 +00:00
|
|
|
} else {
|
2021-06-28 23:01:40 +00:00
|
|
|
files = opts["files"];
|
2021-06-14 14:40:10 +00:00
|
|
|
}
|
2021-06-28 23:01:40 +00:00
|
|
|
files = files.filter(file => path.extname(file) == ".goml");
|
2021-06-25 07:59:04 +00:00
|
|
|
if (files.length === 0) {
|
2021-07-01 14:30:28 +00:00
|
|
|
console.error("rustdoc-gui: No test selected");
|
2021-06-25 07:59:04 +00:00
|
|
|
process.exit(2);
|
|
|
|
}
|
2021-05-07 14:51:00 +00:00
|
|
|
files.sort();
|
2021-06-25 07:59:04 +00:00
|
|
|
|
2021-07-01 14:30:28 +00:00
|
|
|
console.log(`Running ${files.length} rustdoc-gui tests...`);
|
2021-06-25 07:59:04 +00:00
|
|
|
process.setMaxListeners(files.length + 1);
|
2021-06-28 23:01:40 +00:00
|
|
|
let tests = [];
|
|
|
|
let results = new Array(files.length);
|
|
|
|
// poormans enum
|
|
|
|
const RUN_SUCCESS = 42, RUN_FAILED = 23, RUN_ERRORED = 13;
|
|
|
|
for (let i = 0; i < files.length; ++i) {
|
2021-05-07 14:51:00 +00:00
|
|
|
const testPath = path.join(opts["tests_folder"], files[i]);
|
2021-06-28 23:01:40 +00:00
|
|
|
tests.push(
|
|
|
|
runTest(testPath, options)
|
|
|
|
.then(out => {
|
|
|
|
const [output, nb_failures] = out;
|
|
|
|
results[i] = {
|
|
|
|
status: nb_failures === 0 ? RUN_SUCCESS : RUN_FAILED,
|
|
|
|
output: output,
|
|
|
|
};
|
|
|
|
if (nb_failures > 0) {
|
|
|
|
print_test_erroneous()
|
|
|
|
failed = true;
|
|
|
|
} else {
|
|
|
|
print_test_successful()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
results[i] = {
|
|
|
|
status: RUN_ERRORED,
|
|
|
|
output: err,
|
|
|
|
};
|
|
|
|
print_test_erroneous();
|
2021-05-07 14:51:00 +00:00
|
|
|
failed = true;
|
2021-06-28 23:01:40 +00:00
|
|
|
})
|
|
|
|
);
|
2021-06-28 23:41:39 +00:00
|
|
|
if (no_headless) {
|
|
|
|
await tests[i];
|
|
|
|
}
|
2021-05-07 14:51:00 +00:00
|
|
|
}
|
2021-06-28 23:01:40 +00:00
|
|
|
await Promise.all(tests);
|
|
|
|
// final \n after the tests
|
|
|
|
console.log("\n");
|
|
|
|
|
|
|
|
results.forEach(r => {
|
|
|
|
switch (r.status) {
|
|
|
|
case RUN_SUCCESS:
|
|
|
|
if (debug === false) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RUN_FAILED:
|
|
|
|
console.log(r.output);
|
|
|
|
break;
|
|
|
|
case RUN_ERRORED:
|
|
|
|
// skip
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.error(`unexpected status = ${r.status}`);
|
|
|
|
process.exit(4);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// print run errors on the bottom so developers see them better
|
|
|
|
results.forEach(r => {
|
2021-07-01 14:30:28 +00:00
|
|
|
if (r.status === RUN_ERRORED) {
|
|
|
|
console.error(r.output);
|
2021-06-28 23:01:40 +00:00
|
|
|
}
|
|
|
|
});
|
2021-06-25 07:59:04 +00:00
|
|
|
|
2021-05-07 14:51:00 +00:00
|
|
|
if (failed) {
|
2021-02-21 13:21:04 +00:00
|
|
|
process.exit(1);
|
2021-05-07 14:51:00 +00:00
|
|
|
}
|
2021-02-21 13:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main(process.argv);
|