Skip to content

Commit c4d342e

Browse files
authored
Rollup merge of rust-lang#58330 - GuillaumeGomez:rustdoc-js-non-std, r=QuietMisdreavus,Mark-Simulacrum
Add rustdoc JS non-std tests @QuietMisdreavus: You asked it, here it is! r? @QuietMisdreavus
2 parents a0f4e6a + d6add90 commit c4d342e

28 files changed

+455
-39
lines changed

src/bootstrap/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ impl<'a> Builder<'a> {
405405
test::Miri,
406406
test::Clippy,
407407
test::CompiletestTest,
408-
test::RustdocJS,
408+
test::RustdocJSStd,
409+
test::RustdocJSNotStd,
409410
test::RustdocTheme,
410411
// Run bootstrap close to the end as it's unlikely to fail
411412
test::Bootstrap,

src/bootstrap/test.rs

+53-9
Original file line numberDiff line numberDiff line change
@@ -574,22 +574,22 @@ impl Step for RustdocTheme {
574574
}
575575

576576
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
577-
pub struct RustdocJS {
577+
pub struct RustdocJSStd {
578578
pub host: Interned<String>,
579579
pub target: Interned<String>,
580580
}
581581

582-
impl Step for RustdocJS {
582+
impl Step for RustdocJSStd {
583583
type Output = ();
584584
const DEFAULT: bool = true;
585585
const ONLY_HOSTS: bool = true;
586586

587587
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
588-
run.path("src/test/rustdoc-js")
588+
run.path("src/test/rustdoc-js-std")
589589
}
590590

591591
fn make_run(run: RunConfig<'_>) {
592-
run.builder.ensure(RustdocJS {
592+
run.builder.ensure(RustdocJSStd {
593593
host: run.host,
594594
target: run.target,
595595
});
@@ -598,12 +598,55 @@ impl Step for RustdocJS {
598598
fn run(self, builder: &Builder<'_>) {
599599
if let Some(ref nodejs) = builder.config.nodejs {
600600
let mut command = Command::new(nodejs);
601-
command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
601+
command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]);
602602
builder.ensure(crate::doc::Std {
603603
target: self.target,
604604
stage: builder.top_stage,
605605
});
606606
builder.run(&mut command);
607+
} else {
608+
builder.info(
609+
"No nodejs found, skipping \"src/test/rustdoc-js-std\" tests"
610+
);
611+
}
612+
}
613+
}
614+
615+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
616+
pub struct RustdocJSNotStd {
617+
pub host: Interned<String>,
618+
pub target: Interned<String>,
619+
pub compiler: Compiler,
620+
}
621+
622+
impl Step for RustdocJSNotStd {
623+
type Output = ();
624+
const DEFAULT: bool = true;
625+
const ONLY_HOSTS: bool = true;
626+
627+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
628+
run.path("src/test/rustdoc-js")
629+
}
630+
631+
fn make_run(run: RunConfig<'_>) {
632+
let compiler = run.builder.compiler(run.builder.top_stage, run.host);
633+
run.builder.ensure(RustdocJSNotStd {
634+
host: run.host,
635+
target: run.target,
636+
compiler,
637+
});
638+
}
639+
640+
fn run(self, builder: &Builder<'_>) {
641+
if builder.config.nodejs.is_some() {
642+
builder.ensure(Compiletest {
643+
compiler: self.compiler,
644+
target: self.target,
645+
mode: "js-doc-test",
646+
suite: "rustdoc-js",
647+
path: None,
648+
compare_mode: None,
649+
});
607650
} else {
608651
builder.info(
609652
"No nodejs found, skipping \"src/test/rustdoc-js\" tests"
@@ -990,12 +1033,13 @@ impl Step for Compiletest {
9901033
.arg(builder.sysroot_libdir(compiler, target));
9911034
cmd.arg("--rustc-path").arg(builder.rustc(compiler));
9921035

993-
let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
1036+
let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
9941037

9951038
// Avoid depending on rustdoc when we don't need it.
9961039
if mode == "rustdoc"
9971040
|| (mode == "run-make" && suite.ends_with("fulldeps"))
998-
|| (mode == "ui" && is_rustdoc_ui)
1041+
|| (mode == "ui" && is_rustdoc)
1042+
|| mode == "js-doc-test"
9991043
{
10001044
cmd.arg("--rustdoc-path")
10011045
.arg(builder.rustdoc(compiler.host));
@@ -1029,12 +1073,12 @@ impl Step for Compiletest {
10291073
cmd.arg("--nodejs").arg(nodejs);
10301074
}
10311075

1032-
let mut flags = if is_rustdoc_ui {
1076+
let mut flags = if is_rustdoc {
10331077
Vec::new()
10341078
} else {
10351079
vec!["-Crpath".to_string()]
10361080
};
1037-
if !is_rustdoc_ui {
1081+
if !is_rustdoc {
10381082
if builder.config.rust_optimize_tests {
10391083
flags.push("-O".to_string());
10401084
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/rustdoc-js-std/basic.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const QUERY = 'String';
2+
3+
const EXPECTED = {
4+
'others': [
5+
{ 'path': 'std::string', 'name': 'String' },
6+
{ 'path': 'std::ffi', 'name': 'CString' },
7+
{ 'path': 'std::ffi', 'name': 'OsString' },
8+
],
9+
'in_args': [
10+
{ 'path': 'std::str', 'name': 'eq' },
11+
],
12+
'returned': [
13+
{ 'path': 'std::string::String', 'name': 'add' },
14+
],
15+
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/rustdoc-js/basic.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
const QUERY = 'String';
1+
const QUERY = 'Fo';
22

33
const EXPECTED = {
44
'others': [
5-
{ 'path': 'std::string', 'name': 'String' },
6-
{ 'path': 'std::ffi', 'name': 'CString' },
7-
{ 'path': 'std::ffi', 'name': 'OsString' },
8-
],
9-
'in_args': [
10-
{ 'path': 'std::str', 'name': 'eq' },
11-
],
12-
'returned': [
13-
{ 'path': 'std::string::String', 'name': 'add' },
5+
{ 'path': 'basic', 'name': 'Foo' },
146
],
157
};

src/test/rustdoc-js/basic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// Foo
2+
pub struct Foo;

src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub enum Mode {
2424
Incremental,
2525
RunMake,
2626
Ui,
27+
JsDocTest,
2728
MirOpt,
2829
}
2930

@@ -59,6 +60,7 @@ impl FromStr for Mode {
5960
"incremental" => Ok(Incremental),
6061
"run-make" => Ok(RunMake),
6162
"ui" => Ok(Ui),
63+
"js-doc-test" => Ok(JsDocTest),
6264
"mir-opt" => Ok(MirOpt),
6365
_ => Err(()),
6466
}
@@ -82,6 +84,7 @@ impl fmt::Display for Mode {
8284
Incremental => "incremental",
8385
RunMake => "run-make",
8486
Ui => "ui",
87+
JsDocTest => "js-doc-test",
8588
MirOpt => "mir-opt",
8689
};
8790
fmt::Display::fmt(s, f)

src/tools/compiletest/src/runtest.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::common::{output_base_dir, output_base_name, output_testname_unique};
44
use crate::common::{Codegen, CodegenUnits, DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Rustdoc};
55
use crate::common::{CompileFail, Pretty, RunFail, RunPass, RunPassValgrind};
66
use crate::common::{Config, TestPaths};
7-
use crate::common::{Incremental, MirOpt, RunMake, Ui};
7+
use crate::common::{Incremental, MirOpt, RunMake, Ui, JsDocTest};
88
use diff;
99
use crate::errors::{self, Error, ErrorKind};
1010
use filetime::FileTime;
@@ -275,6 +275,7 @@ impl<'test> TestCx<'test> {
275275
RunMake => self.run_rmake_test(),
276276
RunPass | Ui => self.run_ui_test(),
277277
MirOpt => self.run_mir_opt_test(),
278+
JsDocTest => self.run_js_doc_test(),
278279
}
279280
}
280281

@@ -291,6 +292,7 @@ impl<'test> TestCx<'test> {
291292
match self.config.mode {
292293
CompileFail => self.props.compile_pass,
293294
RunPass => true,
295+
JsDocTest => true,
294296
Ui => self.props.compile_pass,
295297
Incremental => {
296298
let revision = self.revision
@@ -1712,7 +1714,8 @@ impl<'test> TestCx<'test> {
17121714
}
17131715

17141716
fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation) -> Command {
1715-
let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui");
1717+
let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui") ||
1718+
self.config.src_base.ends_with("rustdoc-js");
17161719
let mut rustc = if !is_rustdoc {
17171720
Command::new(&self.config.rustc_path)
17181721
} else {
@@ -1802,7 +1805,7 @@ impl<'test> TestCx<'test> {
18021805
rustc.arg(dir_opt);
18031806
}
18041807
RunFail | RunPassValgrind | Pretty | DebugInfoBoth | DebugInfoGdb | DebugInfoLldb
1805-
| Codegen | Rustdoc | RunMake | CodegenUnits => {
1808+
| Codegen | Rustdoc | RunMake | CodegenUnits | JsDocTest => {
18061809
// do not use JSON output
18071810
}
18081811
}
@@ -2710,6 +2713,27 @@ impl<'test> TestCx<'test> {
27102713
fs::remove_dir(path)
27112714
}
27122715

2716+
fn run_js_doc_test(&self) {
2717+
if let Some(nodejs) = &self.config.nodejs {
2718+
let out_dir = self.output_base_dir();
2719+
2720+
self.document(&out_dir);
2721+
2722+
let root = self.config.find_rust_src_root().unwrap();
2723+
let res = self.cmd2procres(
2724+
Command::new(&nodejs)
2725+
.arg(root.join("src/tools/rustdoc-js/tester.js"))
2726+
.arg(out_dir.parent().expect("no parent"))
2727+
.arg(&self.testpaths.file.file_stem().expect("couldn't get file stem")),
2728+
);
2729+
if !res.status.success() {
2730+
self.fatal_proc_rec("rustdoc-js test failed!", &res);
2731+
}
2732+
} else {
2733+
self.fatal("no nodeJS");
2734+
}
2735+
}
2736+
27132737
fn run_ui_test(&self) {
27142738
// if the user specified a format in the ui test
27152739
// print the output to the stderr file, otherwise extract

0 commit comments

Comments
 (0)