Move rustdoc-js testing into compiletest

This commit is contained in:
Guillaume Gomez 2019-02-28 18:08:48 +01:00
parent 240fad04f1
commit 405d950802
4 changed files with 42 additions and 53 deletions

View file

@ -4,7 +4,7 @@
//! our CI.
use std::env;
use std::ffi::{OsStr, OsString};
use std::ffi::OsString;
use std::fmt;
use std::fs;
use std::iter;
@ -638,52 +638,15 @@ impl Step for RustdocJSNotStd {
}
fn run(self, builder: &Builder<'_>) {
if let Some(ref nodejs) = builder.config.nodejs {
builder.ensure(crate::doc::Std {
if builder.config.nodejs.is_some() {
builder.ensure(Compiletest {
compiler: self.compiler,
target: self.target,
stage: builder.top_stage,
mode: "js-doc-test",
suite: "rustdoc-js",
path: None,
compare_mode: None,
});
let mut tests_to_run = Vec::new();
let out = Path::new("build").join(&*self.host)
.join(&format!("stage{}",
builder.top_stage.to_string().as_str()))
.join("tests")
.join("rustdoc-js");
if let Ok(it) = fs::read_dir("src/test/rustdoc-js/") {
for entry in it {
if let Ok(entry) = entry {
let path = entry.path();
if path.extension() != Some(&OsStr::new("rs")) || !path.is_file() {
continue
}
let path_clone = path.clone();
let file_stem = path_clone.file_stem().expect("cannot get file stem");
let out = out.join(file_stem);
let mut cmd = builder.rustdoc_cmd(self.host);
cmd.arg("-o");
cmd.arg(out);
cmd.arg(path);
if if builder.config.verbose_tests {
try_run(builder, &mut cmd)
} else {
try_run_quiet(builder, &mut cmd)
} {
tests_to_run.push(file_stem.to_os_string());
}
}
}
}
assert!(!tests_to_run.is_empty(), "no rustdoc-js test generated...");
tests_to_run.insert(0, "src/tools/rustdoc-js/tester.js".into());
tests_to_run.insert(1, out.into());
let mut command = Command::new(nodejs);
command.args(&tests_to_run);
builder.run(&mut command);
} else {
builder.info(
"No nodejs found, skipping \"src/test/rustdoc-js\" tests"
@ -1070,12 +1033,13 @@ impl Step for Compiletest {
.arg(builder.sysroot_libdir(compiler, target));
cmd.arg("--rustc-path").arg(builder.rustc(compiler));
let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
// Avoid depending on rustdoc when we don't need it.
if mode == "rustdoc"
|| (mode == "run-make" && suite.ends_with("fulldeps"))
|| (mode == "ui" && is_rustdoc_ui)
|| (mode == "ui" && is_rustdoc)
|| mode == "js-doc-test"
{
cmd.arg("--rustdoc-path")
.arg(builder.rustdoc(compiler.host));
@ -1109,12 +1073,12 @@ impl Step for Compiletest {
cmd.arg("--nodejs").arg(nodejs);
}
let mut flags = if is_rustdoc_ui {
let mut flags = if is_rustdoc {
Vec::new()
} else {
vec!["-Crpath".to_string()]
};
if !is_rustdoc_ui {
if !is_rustdoc {
if builder.config.rust_optimize_tests {
flags.push("-O".to_string());
}

View file

@ -1 +1,2 @@
/// Foo
pub struct Foo;

View file

@ -24,6 +24,7 @@ pub enum Mode {
Incremental,
RunMake,
Ui,
JsDocTest,
MirOpt,
}
@ -59,6 +60,7 @@ impl FromStr for Mode {
"incremental" => Ok(Incremental),
"run-make" => Ok(RunMake),
"ui" => Ok(Ui),
"js-doc-test" => Ok(JsDocTest),
"mir-opt" => Ok(MirOpt),
_ => Err(()),
}
@ -82,6 +84,7 @@ impl fmt::Display for Mode {
Incremental => "incremental",
RunMake => "run-make",
Ui => "ui",
JsDocTest => "js-doc-test",
MirOpt => "mir-opt",
};
fmt::Display::fmt(s, f)

View file

@ -4,7 +4,7 @@ use crate::common::{output_base_dir, output_base_name, output_testname_unique};
use crate::common::{Codegen, CodegenUnits, DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Rustdoc};
use crate::common::{CompileFail, Pretty, RunFail, RunPass, RunPassValgrind};
use crate::common::{Config, TestPaths};
use crate::common::{Incremental, MirOpt, RunMake, Ui};
use crate::common::{Incremental, MirOpt, RunMake, Ui, JsDocTest};
use diff;
use crate::errors::{self, Error, ErrorKind};
use filetime::FileTime;
@ -275,6 +275,7 @@ impl<'test> TestCx<'test> {
RunMake => self.run_rmake_test(),
RunPass | Ui => self.run_ui_test(),
MirOpt => self.run_mir_opt_test(),
JsDocTest => self.run_js_doc_test(),
}
}
@ -290,7 +291,7 @@ impl<'test> TestCx<'test> {
fn should_compile_successfully(&self) -> bool {
match self.config.mode {
CompileFail => self.props.compile_pass,
RunPass => true,
RunPass | JsDocTest => true,
Ui => self.props.compile_pass,
Incremental => {
let revision = self.revision
@ -1712,7 +1713,8 @@ impl<'test> TestCx<'test> {
}
fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation) -> Command {
let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui");
let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui") ||
self.config.src_base.ends_with("rustdoc-js");
let mut rustc = if !is_rustdoc {
Command::new(&self.config.rustc_path)
} else {
@ -1802,7 +1804,7 @@ impl<'test> TestCx<'test> {
rustc.arg(dir_opt);
}
RunFail | RunPassValgrind | Pretty | DebugInfoBoth | DebugInfoGdb | DebugInfoLldb
| Codegen | Rustdoc | RunMake | CodegenUnits => {
| Codegen | Rustdoc | RunMake | CodegenUnits | JsDocTest => {
// do not use JSON output
}
}
@ -2710,6 +2712,25 @@ impl<'test> TestCx<'test> {
fs::remove_dir(path)
}
fn run_js_doc_test(&self) {
if let Some(nodejs) = &self.config.nodejs {
let out_dir = self.output_base_dir();
self.document(&out_dir);
let root = self.config.find_rust_src_root().unwrap();
let res = self.cmd2procres(
Command::new(&nodejs)
.arg(root.join("src/tools/rustdoc-js/tester.js"))
.arg(out_dir.parent().expect("no parent"))
.arg(&self.testpaths.file.file_stem().expect("couldn't get file stem")),
);
if !res.status.success() {
self.fatal_proc_rec("rustdoc-js test failed!", &res);
}
}
}
fn run_ui_test(&self) {
// if the user specified a format in the ui test
// print the output to the stderr file, otherwise extract