about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-02-22 06:47:59 +0000
committerbors <bors@rust-lang.org>2021-02-22 06:47:59 +0000
commit352238d152b6b3f106554e75445bbdd5201671b2 (patch)
tree146cb88c6a6c29e8f94b7aa17a07874d5b6bc230 /src/tools
parente952db8fd02090a10024ae63ba9d34e3b9cef898 (diff)
parent20f2497efd5e74bdbf775f8de144ed5c3e3394e8 (diff)
downloadrust-352238d152b6b3f106554e75445bbdd5201671b2.tar.gz
rust-352238d152b6b3f106554e75445bbdd5201671b2.zip
Auto merge of #79979 - GuillaumeGomez:rustdoc-gui-tests, r=Mark-Simulacrum
Rustdoc gui tests

This is a reopening of #70533.

For this first version, there will be no screenshot comparison. Also, a big change compared to the previous version: the tests are now hosted in the rust repository directly. Since there is no image, it's pretty lightweight to say the least.

So now, only remains the nodejs script to run the tests and the tests themselves. Just one thing is missing: where should I put the documentation for these tests? I'm not sure where would be the best place for that. The doc will contain important information like the documentation of the framework used and how to install it (`npm install browser-ui-test`, but still needs to be put somewhere so no one is lost).

We'd also need to install the package when running the CI too. For now, it runs as long as we have nodejs installed, but I think we don't it to run in all nodejs targets?

cc `@jyn514`

r? `@Mark-Simulacrum`
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/compiletest/src/common.rs2
-rw-r--r--src/tools/compiletest/src/main.rs2
-rw-r--r--src/tools/compiletest/src/runtest.rs2
-rw-r--r--src/tools/rustdoc-gui/tester.js89
4 files changed, 94 insertions, 1 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs
index cde4bfe288d..99cbcf316a2 100644
--- a/src/tools/compiletest/src/common.rs
+++ b/src/tools/compiletest/src/common.rs
@@ -344,6 +344,8 @@ pub struct Config {
 
     /// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests
     pub nodejs: Option<String>,
+    /// Path to a npm executable. Used for rustdoc GUI tests
+    pub npm: Option<String>,
 }
 
 #[derive(Debug, Clone)]
diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs
index 3fde24e8a7f..5f263ea87db 100644
--- a/src/tools/compiletest/src/main.rs
+++ b/src/tools/compiletest/src/main.rs
@@ -126,6 +126,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
         .reqopt("", "llvm-components", "list of LLVM components built in", "LIST")
         .optopt("", "llvm-bin-dir", "Path to LLVM's `bin` directory", "PATH")
         .optopt("", "nodejs", "the name of nodejs", "PATH")
+        .optopt("", "npm", "the name of npm", "PATH")
         .optopt("", "remote-test-client", "path to the remote test client", "PATH")
         .optopt(
             "",
@@ -264,6 +265,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
         linker: matches.opt_str("linker"),
         llvm_components: matches.opt_str("llvm-components").unwrap(),
         nodejs: matches.opt_str("nodejs"),
+        npm: matches.opt_str("npm"),
     }
 }
 
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 1ec32184d98..61b21bce10b 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -1585,7 +1585,7 @@ impl<'test> TestCx<'test> {
 
         let aux_dir = self.aux_output_dir_name();
 
-        let rustdoc_path = self.config.rustdoc_path.as_ref().expect("--rustdoc-path passed");
+        let rustdoc_path = self.config.rustdoc_path.as_ref().expect("--rustdoc-path not passed");
         let mut rustdoc = Command::new(rustdoc_path);
 
         rustdoc
diff --git a/src/tools/rustdoc-gui/tester.js b/src/tools/rustdoc-gui/tester.js
new file mode 100644
index 00000000000..a67e2455478
--- /dev/null
+++ b/src/tools/rustdoc-gui/tester.js
@@ -0,0 +1,89 @@
+// This package needs to be install:
+//
+// ```
+// npm install browser-ui-test
+// ```
+const path = require('path');
+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");
+    console.log("  --help                     : show this message then quit");
+    console.log("  --test-file [PATH]         : location of the JS test file");
+}
+
+function parseOptions(args) {
+    var opts = {
+        "doc_folder": "",
+        "test_file": "",
+    };
+    var correspondances = {
+        "--doc-folder": "doc_folder",
+        "--test-file": "test_file",
+    };
+
+    for (var i = 0; i < args.length; ++i) {
+        if (args[i] === "--doc-folder"
+            || args[i] === "--test-file") {
+            i += 1;
+            if (i >= args.length) {
+                console.log("Missing argument after `" + args[i - 1] + "` option.");
+                return null;
+            }
+            opts[correspondances[args[i - 1]]] = args[i];
+        } else if (args[i] === "--help") {
+            showHelp();
+            process.exit(0);
+        } else {
+            console.log("Unknown option `" + args[i] + "`.");
+            console.log("Use `--help` to see the list of options");
+            return null;
+        }
+    }
+    if (opts["test_file"].length < 1) {
+        console.log("Missing `--test-file` option.");
+    } else if (opts["doc_folder"].length < 1) {
+        console.log("Missing `--doc-folder` option.");
+    } else {
+        return opts;
+    }
+    return null;
+}
+
+function checkFile(test_file, opts, loaded, index) {
+    const test_name = path.basename(test_file, ".js");
+
+    process.stdout.write('Checking "' + test_name + '" ... ');
+    return runChecks(test_file, loaded, index);
+}
+
+function main(argv) {
+    var opts = parseOptions(argv.slice(2));
+    if (opts === null) {
+        process.exit(1);
+    }
+
+    const options = new Options();
+    try {
+        // This is more convenient that setting fields one by one.
+        options.parseArguments([
+            '--no-screenshot',
+            "--variable", "DOC_PATH", opts["doc_folder"],
+        ]);
+    } catch (error) {
+        console.error(`invalid argument: ${error}`);
+        process.exit(1);
+    }
+
+    runTest(opts["test_file"], options).then(out => {
+        const [output, nb_failures] = out;
+        console.log(output);
+        process.exit(nb_failures);
+    }).catch(err => {
+        console.error(err);
+        process.exit(1);
+    });
+}
+
+main(process.argv);