mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-11 15:23:05 +00:00
Allow to run a specific rustdoc-js* test
This commit is contained in:
parent
489ec310d2
commit
10d65a9636
@ -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<'_>) {
|
||||
@ -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 {
|
||||
@ -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<'_>) {
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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());
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
@ -412,7 +413,7 @@ function parseOptions(args) {
|
||||
"resource_suffix": "",
|
||||
"doc_folder": "",
|
||||
"test_folder": "",
|
||||
"test_file": "",
|
||||
"test_file": [],
|
||||
};
|
||||
var correspondences = {
|
||||
"--resource-suffix": "resource_suffix",
|
||||
@ -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);
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user