]> git.lizzy.rs Git - rust.git/blob - src/tools/rustdoc-gui/tester.js
Rollup merge of #83041 - guswynn:stable_debug_struct, r=m-ou-se
[rust.git] / src / tools / rustdoc-gui / tester.js
1 // This package needs to be install:
2 //
3 // ```
4 // npm install browser-ui-test
5 // ```
6 const path = require('path');
7 const {Options, runTest} = require('browser-ui-test');
8
9 function showHelp() {
10     console.log("rustdoc-js options:");
11     console.log("  --doc-folder [PATH]        : location of the generated doc folder");
12     console.log("  --help                     : show this message then quit");
13     console.log("  --test-file [PATH]         : location of the JS test file");
14 }
15
16 function parseOptions(args) {
17     var opts = {
18         "doc_folder": "",
19         "test_file": "",
20     };
21     var correspondances = {
22         "--doc-folder": "doc_folder",
23         "--test-file": "test_file",
24     };
25
26     for (var i = 0; i < args.length; ++i) {
27         if (args[i] === "--doc-folder"
28             || args[i] === "--test-file") {
29             i += 1;
30             if (i >= args.length) {
31                 console.log("Missing argument after `" + args[i - 1] + "` option.");
32                 return null;
33             }
34             opts[correspondances[args[i - 1]]] = args[i];
35         } else if (args[i] === "--help") {
36             showHelp();
37             process.exit(0);
38         } else {
39             console.log("Unknown option `" + args[i] + "`.");
40             console.log("Use `--help` to see the list of options");
41             return null;
42         }
43     }
44     if (opts["test_file"].length < 1) {
45         console.log("Missing `--test-file` option.");
46     } else if (opts["doc_folder"].length < 1) {
47         console.log("Missing `--doc-folder` option.");
48     } else {
49         return opts;
50     }
51     return null;
52 }
53
54 function checkFile(test_file, opts, loaded, index) {
55     const test_name = path.basename(test_file, ".js");
56
57     process.stdout.write('Checking "' + test_name + '" ... ');
58     return runChecks(test_file, loaded, index);
59 }
60
61 function main(argv) {
62     var opts = parseOptions(argv.slice(2));
63     if (opts === null) {
64         process.exit(1);
65     }
66
67     const options = new Options();
68     try {
69         // This is more convenient that setting fields one by one.
70         options.parseArguments([
71             '--no-screenshot',
72             "--variable", "DOC_PATH", opts["doc_folder"],
73         ]);
74     } catch (error) {
75         console.error(`invalid argument: ${error}`);
76         process.exit(1);
77     }
78
79     runTest(opts["test_file"], options).then(out => {
80         const [output, nb_failures] = out;
81         console.log(output);
82         process.exit(nb_failures);
83     }).catch(err => {
84         console.error(err);
85         process.exit(1);
86     });
87 }
88
89 main(process.argv);