Allow to run a specific rustdoc-js* test

This commit is contained in:
Guillaume Gomez 2021-11-05 15:58:14 +01:00
parent 489ec310d2
commit 10d65a9636
3 changed files with 64 additions and 39 deletions

View file

@ -763,7 +763,7 @@ impl Step for RustdocJSStd {
const ONLY_HOSTS: bool = true; const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/test/rustdoc-js-std") run.suite_path("src/test/rustdoc-js-std")
} }
fn make_run(run: RunConfig<'_>) { fn make_run(run: RunConfig<'_>) {
@ -783,6 +783,17 @@ impl Step for RustdocJSStd {
.arg(builder.doc_out(self.target)) .arg(builder.doc_out(self.target))
.arg("--test-folder") .arg("--test-folder")
.arg(builder.src.join("src/test/rustdoc-js-std")); .arg(builder.src.join("src/test/rustdoc-js-std"));
for path in &builder.paths {
if let Some(p) =
util::is_valid_test_suite_arg(path, "src/test/rustdoc-js-std", builder)
{
if !p.ends_with(".js") {
eprintln!("A non-js file was given: `{}`", path.display());
panic!("Cannot run rustdoc-js-std tests");
}
command.arg("--test-file").arg(path);
}
}
builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage }); builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
builder.run(&mut command); builder.run(&mut command);
} else { } else {
@ -803,7 +814,7 @@ impl Step for RustdocJSNotStd {
const ONLY_HOSTS: bool = true; const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/test/rustdoc-js") run.suite_path("src/test/rustdoc-js")
} }
fn make_run(run: RunConfig<'_>) { fn make_run(run: RunConfig<'_>) {
@ -938,8 +949,12 @@ impl Step for RustdocGUI {
.arg("--tests-folder") .arg("--tests-folder")
.arg(builder.build.src.join("src/test/rustdoc-gui")); .arg(builder.build.src.join("src/test/rustdoc-gui"));
for path in &builder.paths { for path in &builder.paths {
if let Some(p) = util::is_valid_test_suite_arg(path, "src/test/rustdoc-gui", builder) {
if !p.ends_with(".goml") {
eprintln!("A non-goml file was given: `{}`", path.display());
panic!("Cannot run rustdoc-gui tests");
}
if let Some(name) = path.file_name().and_then(|f| f.to_str()) { if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
if name.ends_with(".goml") {
command.arg("--file").arg(name); command.arg("--file").arg(name);
} }
} }
@ -1416,35 +1431,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
// Get test-args by striping suite path // Get test-args by striping suite path
let mut test_args: Vec<&str> = paths let mut test_args: Vec<&str> = paths
.iter() .iter()
.map(|p| match p.strip_prefix(".") { .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
Ok(path) => path,
Err(_) => p,
})
.filter(|p| p.starts_with(suite_path))
.filter(|p| {
let exists = p.is_dir() || p.is_file();
if !exists {
if let Some(p) = p.to_str() {
builder.info(&format!(
"Warning: Skipping \"{}\": not a regular file or directory",
p
));
}
}
exists
})
.filter_map(|p| {
// Since test suite paths are themselves directories, if we don't
// specify a directory or file, we'll get an empty string here
// (the result of the test suite directory without its suite prefix).
// Therefore, we need to filter these out, as only the first --test-args
// flag is respected, so providing an empty --test-args conflicts with
// any following it.
match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
Some(s) if !s.is_empty() => Some(s),
_ => None,
}
})
.collect(); .collect();
test_args.append(&mut builder.config.cmd.test_args()); test_args.append(&mut builder.config.cmd.test_args());

View file

@ -310,3 +310,35 @@ pub fn use_host_linker(target: TargetSelection) -> bool {
|| target.contains("fuchsia") || target.contains("fuchsia")
|| target.contains("bpf")) || target.contains("bpf"))
} }
pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
path: &'a Path,
suite_path: P,
builder: &Builder<'_>,
) -> Option<&'a str> {
let suite_path = suite_path.as_ref();
let path = match path.strip_prefix(".") {
Ok(p) => p,
Err(_) => path,
};
if !path.starts_with(suite_path) {
return None;
}
let exists = path.is_dir() || path.is_file();
if !exists {
if let Some(p) = path.to_str() {
builder.info(&format!("Warning: Skipping \"{}\": not a regular file or directory", p));
}
return None;
}
// Since test suite paths are themselves directories, if we don't
// specify a directory or file, we'll get an empty string here
// (the result of the test suite directory without its suite prefix).
// Therefore, we need to filter these out, as only the first --test-args
// flag is respected, so providing an empty --test-args conflicts with
// any following it.
match path.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
Some(s) if !s.is_empty() => Some(s),
_ => None,
}
}

View file

@ -401,7 +401,8 @@ function showHelp() {
console.log(" --doc-folder [PATH] : location of the generated doc folder"); console.log(" --doc-folder [PATH] : location of the generated doc folder");
console.log(" --help : show this message then quit"); console.log(" --help : show this message then quit");
console.log(" --crate-name [STRING] : crate name to be used"); console.log(" --crate-name [STRING] : crate name to be used");
console.log(" --test-file [PATH] : location of the JS test file"); console.log(" --test-file [PATHs] : location of the JS test files (can be called " +
"multiple times)");
console.log(" --test-folder [PATH] : location of the JS tests folder"); console.log(" --test-folder [PATH] : location of the JS tests folder");
console.log(" --resource-suffix [STRING] : suffix to refer to the correct files"); console.log(" --resource-suffix [STRING] : suffix to refer to the correct files");
} }
@ -412,7 +413,7 @@ function parseOptions(args) {
"resource_suffix": "", "resource_suffix": "",
"doc_folder": "", "doc_folder": "",
"test_folder": "", "test_folder": "",
"test_file": "", "test_file": [],
}; };
var correspondences = { var correspondences = {
"--resource-suffix": "resource_suffix", "--resource-suffix": "resource_suffix",
@ -429,7 +430,11 @@ function parseOptions(args) {
console.log("Missing argument after `" + args[i - 1] + "` option."); console.log("Missing argument after `" + args[i - 1] + "` option.");
return null; return null;
} }
if (args[i - 1] !== "--test-file") {
opts[correspondences[args[i - 1]]] = args[i]; opts[correspondences[args[i - 1]]] = args[i];
} else {
opts[correspondences[args[i - 1]]].push(args[i]);
}
} else if (args[i] === "--help") { } else if (args[i] === "--help") {
showHelp(); showHelp();
process.exit(0); process.exit(0);
@ -471,9 +476,10 @@ function main(argv) {
var errors = 0; var errors = 0;
if (opts["test_file"].length !== 0) { if (opts["test_file"].length !== 0) {
errors += checkFile(opts["test_file"], opts, loaded, index); opts["test_file"].forEach(function(file) {
} errors += checkFile(file, opts, loaded, index);
if (opts["test_folder"].length !== 0) { });
} else if (opts["test_folder"].length !== 0) {
fs.readdirSync(opts["test_folder"]).forEach(function(file) { fs.readdirSync(opts["test_folder"]).forEach(function(file) {
if (!file.endsWith(".js")) { if (!file.endsWith(".js")) {
return; return;