Skip to content

Commit ae05961

Browse files
committed
Make tidy treat "test/ui/foo.nll.stderr" just like "foo.stderr".
1 parent 4b9b70c commit ae05961

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/tools/tidy/src/ui_tests.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,41 @@
1212
1313
use std::path::Path;
1414

15+
// See rust-lang/rust#48879: In addition to the mapping from `foo.rs`
16+
// to `foo.stderr`/`foo.stdout`, we also can optionally have
17+
// `foo.$mode.stderr`, where $mode is one of the strings on this list,
18+
// as an alternative to use when running under that mode.
19+
static COMPARE_MODE_NAMES: [&'static str; 1] = ["nll"];
20+
1521
pub fn check(path: &Path, bad: &mut bool) {
1622
super::walk_many(&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
1723
&mut |_| false,
1824
&mut |file_path| {
1925
if let Some(ext) = file_path.extension() {
2026
if (ext == "stderr" || ext == "stdout") && !file_path.with_extension("rs").exists() {
21-
println!("Stray file with UI testing output: {:?}", file_path);
22-
*bad = true;
27+
28+
// rust-lang/rust#48879: this fn used to be beautful
29+
// because Path API special-cases replacing
30+
// extensions. That works great for ".stderr" but not
31+
// so well for ".nll.stderr". To support the latter,
32+
// we explicitly search backwards for mode's starting
33+
// point and build corresponding source name.
34+
let filename = file_path.file_name().expect("need filename")
35+
.to_str().expect("need UTF-8 filename");
36+
let found_matching_prefix = COMPARE_MODE_NAMES.iter().any(|mode| {
37+
if let Some(r_idx) = filename.rfind(&format!(".{}", mode)) {
38+
let source_name = format!("{}.rs", &filename[0..r_idx]);
39+
let source_path = file_path.with_file_name(source_name);
40+
source_path.exists()
41+
} else {
42+
false
43+
}
44+
});
45+
46+
if !found_matching_prefix {
47+
println!("Stray file with UI testing output: {:?}", file_path);
48+
*bad = true;
49+
}
2350
}
2451
}
2552
});

0 commit comments

Comments
 (0)