Skip to content

Commit b9dbf8e

Browse files
authored
Rollup merge of rust-lang#49812 - ehuss:ui-test-revisions, r=nikomatsakis
Fix revision support for UI tests. Fixes rust-lang#48878
2 parents 91cc872 + c3af118 commit b9dbf8e

File tree

3 files changed

+70
-71
lines changed

3 files changed

+70
-71
lines changed

src/test/ui/update-references.sh

+11-18
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,17 @@ MYDIR=$(dirname $0)
3131
BUILD_DIR="$1"
3232
shift
3333

34+
shopt -s nullglob
35+
3436
while [[ "$1" != "" ]]; do
35-
STDERR_NAME="${1/%.rs/.stderr}"
36-
STDERR_NLL_NAME="${1/%.rs/.nll.stderr}"
37-
STDOUT_NAME="${1/%.rs/.stdout}"
37+
for EXT in "stderr" "stdout"; do
38+
for OUT_NAME in $BUILD_DIR/${1%.rs}.*$EXT; do
39+
OUT_BASE=`basename "$OUT_NAME"`
40+
if ! (diff $OUT_NAME $MYDIR/$OUT_BASE >& /dev/null); then
41+
echo updating $MYDIR/$OUT_BASE
42+
cp $OUT_NAME $MYDIR
43+
fi
44+
done
45+
done
3846
shift
39-
if [ -f $BUILD_DIR/$STDOUT_NAME ] && \
40-
! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then
41-
echo updating $MYDIR/$STDOUT_NAME
42-
cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME
43-
fi
44-
if [ -f $BUILD_DIR/$STDERR_NAME ] && \
45-
! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then
46-
echo updating $MYDIR/$STDERR_NAME
47-
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
48-
fi
49-
if [ -f $BUILD_DIR/$STDERR_NLL_NAME ] && \
50-
! (diff $BUILD_DIR/$STDERR_NLL_NAME $MYDIR/$STDERR_NLL_NAME >& /dev/null); then
51-
echo updating $MYDIR/$STDERR_NLL_NAME
52-
cp $BUILD_DIR/$STDERR_NLL_NAME $MYDIR/$STDERR_NLL_NAME
53-
fi
5447
done

src/tools/compiletest/src/runtest.rs

+44-26
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::collections::VecDeque;
2626
use std::collections::HashMap;
2727
use std::collections::HashSet;
2828
use std::env;
29-
use std::ffi::OsString;
29+
use std::ffi::{OsStr, OsString};
3030
use std::fs::{self, create_dir_all, File};
3131
use std::fmt;
3232
use std::io::prelude::*;
@@ -72,6 +72,26 @@ impl Mismatch {
7272
}
7373
}
7474

75+
trait PathBufExt {
76+
/// Append an extension to the path, even if it already has one.
77+
fn with_extra_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf;
78+
}
79+
80+
impl PathBufExt for PathBuf {
81+
fn with_extra_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
82+
if extension.as_ref().len() == 0 {
83+
self.clone()
84+
} else {
85+
let mut fname = self.file_name().unwrap().to_os_string();
86+
if !extension.as_ref().to_str().unwrap().starts_with(".") {
87+
fname.push(".");
88+
}
89+
fname.push(extension);
90+
self.with_file_name(fname)
91+
}
92+
}
93+
}
94+
7595
// Produces a diff between the expected output and actual output.
7696
pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Mismatch> {
7797
let mut line_number = 1;
@@ -1725,20 +1745,14 @@ impl<'test> TestCx<'test> {
17251745
}
17261746

17271747
fn make_exe_name(&self) -> PathBuf {
1728-
let mut f = self.output_base_name();
1748+
let mut f = self.output_base_name_stage();
17291749
// FIXME: This is using the host architecture exe suffix, not target!
17301750
if self.config.target.contains("emscripten") {
1731-
let mut fname = f.file_name().unwrap().to_os_string();
1732-
fname.push(".js");
1733-
f.set_file_name(&fname);
1751+
f = f.with_extra_extension("js");
17341752
} else if self.config.target.contains("wasm32") {
1735-
let mut fname = f.file_name().unwrap().to_os_string();
1736-
fname.push(".wasm");
1737-
f.set_file_name(&fname);
1753+
f = f.with_extra_extension("wasm");
17381754
} else if !env::consts::EXE_SUFFIX.is_empty() {
1739-
let mut fname = f.file_name().unwrap().to_os_string();
1740-
fname.push(env::consts::EXE_SUFFIX);
1741-
f.set_file_name(&fname);
1755+
f = f.with_extra_extension(env::consts::EXE_SUFFIX);
17421756
}
17431757
f
17441758
}
@@ -1846,25 +1860,28 @@ impl<'test> TestCx<'test> {
18461860
}
18471861

18481862
fn aux_output_dir_name(&self) -> PathBuf {
1849-
let f = self.output_base_name();
1850-
let mut fname = f.file_name().unwrap().to_os_string();
1851-
fname.push(&format!("{}.aux", self.config.mode.disambiguator()));
1852-
f.with_file_name(&fname)
1863+
self.output_base_name_stage()
1864+
.with_extra_extension(self.config.mode.disambiguator())
1865+
.with_extra_extension(".aux")
18531866
}
18541867

18551868
fn output_testname(&self, filepath: &Path) -> PathBuf {
18561869
PathBuf::from(filepath.file_stem().unwrap())
18571870
}
18581871

1859-
/// Given a test path like `compile-fail/foo/bar.rs` Returns a name like
1860-
///
1861-
/// <output>/foo/bar-stage1
1872+
/// Given a test path like `compile-fail/foo/bar.rs` returns a name like
1873+
/// `/path/to/build/<triple>/test/compile-fail/foo/bar`.
18621874
fn output_base_name(&self) -> PathBuf {
18631875
let dir = self.config.build_base.join(&self.testpaths.relative_dir);
18641876

18651877
// Note: The directory `dir` is created during `collect_tests_from_dir`
18661878
dir.join(&self.output_testname(&self.testpaths.file))
1867-
.with_extension(&self.config.stage_id)
1879+
}
1880+
1881+
/// Same as `output_base_name`, but includes the stage ID as an extension,
1882+
/// such as: `.../compile-fail/foo/bar.stage1-<triple>`
1883+
fn output_base_name_stage(&self) -> PathBuf {
1884+
self.output_base_name().with_extension(&self.config.stage_id)
18681885
}
18691886

18701887
fn maybe_dump_to_stdout(&self, out: &str, err: &str) {
@@ -1989,7 +2006,7 @@ impl<'test> TestCx<'test> {
19892006
fn run_rustdoc_test(&self) {
19902007
assert!(self.revision.is_none(), "revisions not relevant here");
19912008

1992-
let out_dir = self.output_base_name();
2009+
let out_dir = self.output_base_name_stage();
19932010
let _ = fs::remove_dir_all(&out_dir);
19942011
create_dir_all(&out_dir).unwrap();
19952012

@@ -2391,7 +2408,7 @@ impl<'test> TestCx<'test> {
23912408
.unwrap();
23922409
let src_root = cwd.join(&src_root);
23932410

2394-
let tmpdir = cwd.join(self.output_base_name());
2411+
let tmpdir = cwd.join(self.output_base_name_stage());
23952412
if tmpdir.exists() {
23962413
self.aggressive_rm_rf(&tmpdir).unwrap();
23972414
}
@@ -2816,7 +2833,6 @@ impl<'test> TestCx<'test> {
28162833
self.revision,
28172834
&self.config.compare_mode,
28182835
kind);
2819-
28202836
if !path.exists() && self.config.compare_mode.is_some() {
28212837
// fallback!
28222838
path = expected_output_path(&self.testpaths, self.revision, &None, kind);
@@ -2880,10 +2896,12 @@ impl<'test> TestCx<'test> {
28802896
}
28812897
}
28822898

2883-
let expected_output = self.expected_output_path(kind);
2884-
// #50113: output is abspath; only want filename component.
2885-
let expected_output = expected_output.file_name().expect("output path requires file name");
2886-
let output_file = self.output_base_name().with_file_name(&expected_output);
2899+
let mode = self.config.compare_mode.as_ref().map_or("", |m| m.to_str());
2900+
let output_file = self.output_base_name()
2901+
.with_extra_extension(self.revision.unwrap_or(""))
2902+
.with_extra_extension(mode)
2903+
.with_extra_extension(kind);
2904+
28872905
match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) {
28882906
Ok(()) => {}
28892907
Err(e) => self.fatal(&format!(

src/tools/tidy/src/ui_tests.rs

+15-27
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,26 @@
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-
2115
pub fn check(path: &Path, bad: &mut bool) {
2216
super::walk_many(&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
2317
&mut |_| false,
2418
&mut |file_path| {
2519
if let Some(ext) = file_path.extension() {
26-
if (ext == "stderr" || ext == "stdout") && !file_path.with_extension("rs").exists() {
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 {
20+
if ext == "stderr" || ext == "stdout" {
21+
// Test output filenames have the format:
22+
// $testname.stderr
23+
// $testname.$mode.stderr
24+
// $testname.$revision.stderr
25+
// $testname.$revision.$mode.stderr
26+
//
27+
// For now, just make sure that there is a corresponding
28+
// $testname.rs file.
29+
let testname = file_path.file_name().unwrap()
30+
.to_str().unwrap()
31+
.splitn(2, '.').next().unwrap();
32+
if !file_path.with_file_name(testname)
33+
.with_extension("rs")
34+
.exists() {
4735
println!("Stray file with UI testing output: {:?}", file_path);
4836
*bad = true;
4937
}

0 commit comments

Comments
 (0)