From f18c52b2233b8d1142fea29551e140fd15d3ae70 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Dec 2017 23:53:24 +0100 Subject: [PATCH] Start adding js tests --- src/bootstrap/check.rs | 35 ++++++++++++++++++++++++++++++++++ src/bootstrap/tool.rs | 1 + src/test/rustdoc-js/basic.js | 15 +++++++++++++++ src/tools/rustdoc-js/tester.js | 26 +++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 src/test/rustdoc-js/basic.js create mode 100644 src/tools/rustdoc-js/tester.js 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, +} + +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, @@ -570,6 +604,7 @@ fn run(self, builder: &Builder) { }, 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 @@ fn run(self, builder: &Builder) -> PathBuf { 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 or the MIT license +// , 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 or the MIT license +// , 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; +});