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(".");
|
|
|
|
}
|
|
|
|
function print_test_erroneous() {
|
|
|
|
// Bold Red "F" Reset
|
|
|
|
process.stdout.write("\033[1m\x1b[31mF\x1b[0m");
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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"]) {
|
|
|
|
args.push("--debug");
|
|
|
|
}
|
|
|
|
if (opts["show_text"]) {
|
|
|
|
args.push("--show-text");
|
|
|
|
}
|
|
|
|
if (opts["no_headless"]) {
|
|
|
|
args.push("--no-headless");
|
|
|
|
}
|
|
|
|
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;
|
2021-06-25 07:59:04 +00:00
|
|
|
let tests = [];
|
2021-06-14 14:40:10 +00:00
|
|
|
if (opts["files"].length === 0) {
|
|
|
|
files = fs.readdirSync(opts["tests_folder"]).filter(file => path.extname(file) == ".goml");
|
|
|
|
} else {
|
|
|
|
files = opts["files"].filter(file => path.extname(file) == ".goml");
|
|
|
|
}
|
2021-06-25 07:59:04 +00:00
|
|
|
if (files.length === 0) {
|
|
|
|
console.log("rustdoc-gui: No test selected");
|
|
|
|
process.exit(2);
|
|
|
|
}
|
2021-05-07 14:51:00 +00:00
|
|
|
files.sort();
|
2021-06-25 07:59:04 +00:00
|
|
|
|
|
|
|
console.log(`running ${files.length} rustdoc-gui tests`);
|
|
|
|
process.setMaxListeners(files.length + 1);
|
2021-05-07 14:51:00 +00:00
|
|
|
for (var i = 0; i < files.length; ++i) {
|
|
|
|
const testPath = path.join(opts["tests_folder"], files[i]);
|
2021-06-25 07:59:04 +00:00
|
|
|
tests.push(runTest(testPath, options));
|
|
|
|
}
|
|
|
|
|
|
|
|
let error_outputs = "";
|
|
|
|
let failed_outputs = "";
|
|
|
|
for (var i = 0; i < tests.length; ++i) {
|
|
|
|
await tests[i].then(out => {
|
2021-05-07 14:51:00 +00:00
|
|
|
const [output, nb_failures] = out;
|
|
|
|
if (nb_failures > 0) {
|
2021-06-25 07:59:04 +00:00
|
|
|
failed_outputs += output + "\n";
|
|
|
|
print_test_erroneous()
|
2021-05-07 14:51:00 +00:00
|
|
|
failed = true;
|
2021-06-25 07:59:04 +00:00
|
|
|
} else {
|
|
|
|
print_test_successful()
|
2021-05-07 14:51:00 +00:00
|
|
|
}
|
|
|
|
}).catch(err => {
|
2021-06-25 07:59:04 +00:00
|
|
|
error_outputs += err + "\n";
|
|
|
|
print_test_erroneous();
|
2021-05-07 14:51:00 +00:00
|
|
|
failed = true;
|
|
|
|
});
|
|
|
|
}
|
2021-06-25 07:59:04 +00:00
|
|
|
console.log("")
|
|
|
|
|
2021-05-07 14:51:00 +00:00
|
|
|
if (failed) {
|
2021-06-25 07:59:04 +00:00
|
|
|
console.log(failed_outputs);
|
|
|
|
console.error(error_outputs);
|
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);
|