Skip to content

Commit f18c52b

Browse files
Start adding js tests
1 parent 0b90e4e commit f18c52b

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

src/bootstrap/check.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,40 @@ fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
424424
env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
425425
}
426426

427+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
428+
pub struct RustdocJS {
429+
pub host: Interned<String>,
430+
}
431+
432+
impl Step for RustdocJS {
433+
type Output = PathBuf;
434+
const DEFAULT: bool = true;
435+
const ONLY_HOSTS: bool = true;
436+
437+
fn should_run(run: ShouldRun) -> ShouldRun {
438+
run.path("node")
439+
}
440+
441+
fn make_run(run: RunConfig) {
442+
run.builder.ensure(RustdocJS {
443+
host: run.host,
444+
});
445+
}
446+
447+
fn run(self, _: &Builder) {
448+
let cmd = if cfg!(target_os = "windows") {
449+
let command = Command::new("cmd");
450+
command.args(&["/C", "node src/tools/rustdoc-js/tester.js"]);
451+
command
452+
} else {
453+
let command = Command::new("sh");
454+
command.args(&["-c", "node src/tools/rustdoc-js/tester.js"]);
455+
command
456+
};
457+
builder.run(cmd);
458+
}
459+
}
460+
427461
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
428462
pub struct Tidy {
429463
host: Interned<String>,
@@ -570,6 +604,7 @@ static HOST_COMPILETESTS: &[Test] = &[
570604
},
571605
Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
572606
Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
607+
Test { path: "src/test/rustdoc-js", mode: "rustdoc-js", suite: "rustdoc-js" },
573608

574609
Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
575610
Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },

src/bootstrap/tool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ tool!(
260260
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::Libstd;
261261
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::Libstd;
262262
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::Libstd;
263+
RustdocJS, "node", "node", Mode::Tool;
263264
);
264265

265266
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]

src/test/rustdoc-js/basic.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const QUERY = 'String';
12+
13+
const EXPECTED = [
14+
{'all': ['std::string::String']},
15+
];

src/tools/rustdoc-js/tester.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const fs = require('fs');
12+
13+
const TEST_FOLDER = 'src/test/rustdoc-js/';
14+
15+
function loadFile(filePath) {
16+
var src = fs.readFileSync(filePath, 'utf8').split('\n').slice(15, -10).join('\n');
17+
var Module = module.constructor;
18+
var m = new Module();
19+
m._compile(src, filePath);
20+
return m;
21+
}
22+
23+
fs.readdirSync(TEST_FOLDER).forEach(function(file) {
24+
var file = require(TEST_FOLDER + file);
25+
const expected = file.EXPECTED;
26+
});

0 commit comments

Comments
 (0)