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

Make tidy treat "test/ui/foo.nll.stderr" just like "foo.stderr". #49844

Closed
wants to merge 2 commits into from
Closed
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
31 changes: 29 additions & 2 deletions src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,41 @@

use std::path::Path;

// See rust-lang/rust#48879: In addition to the mapping from `foo.rs`
// to `foo.stderr`/`foo.stdout`, we also can optionally have
// `foo.$mode.stderr`, where $mode is one of the strings on this list,
// as an alternative to use when running under that mode.
static COMPARE_MODE_NAMES: [&'static str; 1] = ["nll"];

pub fn check(path: &Path, bad: &mut bool) {
super::walk_many(&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
&mut |_| false,
&mut |file_path| {
if let Some(ext) = file_path.extension() {
if (ext == "stderr" || ext == "stdout") && !file_path.with_extension("rs").exists() {
println!("Stray file with UI testing output: {:?}", file_path);
*bad = true;

// rust-lang/rust#48879: this fn used to be beautiful
// because Path API special-cases replacing
// extensions. That works great for ".stderr" but not
// so well for ".nll.stderr". To support the latter,
// we explicitly search backwards for mode's starting
// point and build corresponding source name.
let filename = file_path.file_name().expect("need filename")
.to_str().expect("need UTF-8 filename");
let found_matching_prefix = COMPARE_MODE_NAMES.iter().any(|mode| {
if let Some(r_idx) = filename.rfind(&format!(".{}", mode)) {
let source_name = format!("{}.rs", &filename[0..r_idx]);
let source_path = file_path.with_file_name(source_name);
source_path.exists()
} else {
false
}
});

if !found_matching_prefix {
println!("Stray file with UI testing output: {:?}", file_path);
*bad = true;
}
}
}
});
Expand Down