Skip to content

Commit

Permalink
Make tidy treat "test/ui/foo.nll.stderr" just like "foo.stderr".
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Apr 9, 2018
1 parent 4b9b70c commit ae05961
Showing 1 changed file with 29 additions and 2 deletions.
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 beautful
// 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

0 comments on commit ae05961

Please sign in to comment.