|
12 | 12 |
|
13 | 13 | use std::path::Path;
|
14 | 14 |
|
| 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 | + |
15 | 21 | pub fn check(path: &Path, bad: &mut bool) {
|
16 | 22 | super::walk_many(&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
|
17 | 23 | &mut |_| false,
|
18 | 24 | &mut |file_path| {
|
19 | 25 | if let Some(ext) = file_path.extension() {
|
20 | 26 | 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 | + } |
23 | 50 | }
|
24 | 51 | }
|
25 | 52 | });
|
|
0 commit comments