Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to run a specific rustdoc-js* test #90613

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 20 additions & 33 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ impl Step for RustdocJSStd {
const ONLY_HOSTS: bool = true;

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<'_>) {
Expand All @@ -783,6 +783,17 @@ impl Step for RustdocJSStd {
.arg(builder.doc_out(self.target))
.arg("--test-folder")
.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.run(&mut command);
} else {
Expand All @@ -803,7 +814,7 @@ impl Step for RustdocJSNotStd {
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/test/rustdoc-js")
run.suite_path("src/test/rustdoc-js")
}

fn make_run(run: RunConfig<'_>) {
Expand Down Expand Up @@ -938,8 +949,12 @@ impl Step for RustdocGUI {
.arg("--tests-folder")
.arg(builder.build.src.join("src/test/rustdoc-gui"));
for path in &builder.paths {
if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
if name.ends_with(".goml") {
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()) {
command.arg("--file").arg(name);
}
}
Expand Down Expand Up @@ -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
let mut test_args: Vec<&str> = paths
.iter()
.map(|p| match p.strip_prefix(".") {
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,
}
})
.filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
.collect();

test_args.append(&mut builder.config.cmd.test_args());
Expand Down
32 changes: 32 additions & 0 deletions src/bootstrap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,35 @@ pub fn use_host_linker(target: TargetSelection) -> bool {
|| target.contains("fuchsia")
|| 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,
}
}
18 changes: 12 additions & 6 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ function showHelp() {
console.log(" --doc-folder [PATH] : location of the generated doc folder");
console.log(" --help : show this message then quit");
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(" --resource-suffix [STRING] : suffix to refer to the correct files");
}
Expand All @@ -412,7 +413,7 @@ function parseOptions(args) {
"resource_suffix": "",
"doc_folder": "",
"test_folder": "",
"test_file": "",
"test_file": [],
};
var correspondences = {
"--resource-suffix": "resource_suffix",
Expand All @@ -429,7 +430,11 @@ function parseOptions(args) {
console.log("Missing argument after `" + args[i - 1] + "` option.");
return null;
}
opts[correspondences[args[i - 1]]] = args[i];
if (args[i - 1] !== "--test-file") {
opts[correspondences[args[i - 1]]] = args[i];
} else {
opts[correspondences[args[i - 1]]].push(args[i]);
}
} else if (args[i] === "--help") {
showHelp();
process.exit(0);
Expand Down Expand Up @@ -471,9 +476,10 @@ function main(argv) {
var errors = 0;

if (opts["test_file"].length !== 0) {
errors += checkFile(opts["test_file"], opts, loaded, index);
}
if (opts["test_folder"].length !== 0) {
opts["test_file"].forEach(function(file) {
errors += checkFile(file, opts, loaded, index);
});
} else if (opts["test_folder"].length !== 0) {
fs.readdirSync(opts["test_folder"]).forEach(function(file) {
if (!file.endsWith(".js")) {
return;
Expand Down