about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-12-12 23:53:24 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2018-01-12 22:51:34 +0100
commitf18c52b2233b8d1142fea29551e140fd15d3ae70 (patch)
tree6ae49b233052cf7d4c8d9c8479bf94686e9d21d4
parent0b90e4e8cd068910f604f3e1fb5d03cc01f1658f (diff)
downloadrust-f18c52b2233b8d1142fea29551e140fd15d3ae70.tar.gz
rust-f18c52b2233b8d1142fea29551e140fd15d3ae70.zip
Start adding js tests
-rw-r--r--src/bootstrap/check.rs35
-rw-r--r--src/bootstrap/tool.rs1
-rw-r--r--src/test/rustdoc-js/basic.js15
-rw-r--r--src/tools/rustdoc-js/tester.js26
4 files changed, 77 insertions, 0 deletions
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs
index cc9be3cec34..d4be0de6a1e 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -424,6 +424,40 @@ fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
     env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
 }
 
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct RustdocJS {
+    pub host: Interned<String>,
+}
+
+impl Step for RustdocJS {
+    type Output = PathBuf;
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("node")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(RustdocJS {
+            host: run.host,
+        });
+    }
+
+    fn run(self, _: &Builder) {
+        let cmd = if cfg!(target_os = "windows") {
+            let command = Command::new("cmd");
+            command.args(&["/C", "node src/tools/rustdoc-js/tester.js"]);
+            command
+        } else {
+            let command = Command::new("sh");
+            command.args(&["-c", "node src/tools/rustdoc-js/tester.js"]);
+            command
+        };
+        builder.run(cmd);
+    }
+}
+
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub struct Tidy {
     host: Interned<String>,
@@ -570,6 +604,7 @@ static HOST_COMPILETESTS: &[Test] = &[
     },
     Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
     Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
+    Test { path: "src/test/rustdoc-js", mode: "rustdoc-js", suite: "rustdoc-js" },
 
     Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
     Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index ea055cb5d1b..d80d7732ab2 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -260,6 +260,7 @@ tool!(
     BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::Libstd;
     RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::Libstd;
     RustInstaller, "src/tools/rust-installer", "fabricate", Mode::Libstd;
+    RustdocJS, "node", "node", Mode::Tool;
 );
 
 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
diff --git a/src/test/rustdoc-js/basic.js b/src/test/rustdoc-js/basic.js
new file mode 100644
index 00000000000..2eada17f0db
--- /dev/null
+++ b/src/test/rustdoc-js/basic.js
@@ -0,0 +1,15 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+const QUERY = 'String';
+
+const EXPECTED = [
+    {'all': ['std::string::String']},
+];
diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js
new file mode 100644
index 00000000000..9789c007d16
--- /dev/null
+++ b/src/tools/rustdoc-js/tester.js
@@ -0,0 +1,26 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+const fs = require('fs');
+
+const TEST_FOLDER = 'src/test/rustdoc-js/';
+
+function loadFile(filePath) {
+    var src = fs.readFileSync(filePath, 'utf8').split('\n').slice(15, -10).join('\n');
+    var Module = module.constructor;
+    var m = new Module();
+    m._compile(src, filePath);
+    return m;
+}
+
+fs.readdirSync(TEST_FOLDER).forEach(function(file) {
+    var file = require(TEST_FOLDER + file);
+    const expected = file.EXPECTED;
+});