Skip to content

Commit 79db5fe

Browse files
committed
add --compare-mode option to compiletest
1 parent b176285 commit 79db5fe

File tree

3 files changed

+64
-20
lines changed

3 files changed

+64
-20
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ impl fmt::Display for Mode {
9595
}
9696
}
9797

98+
#[derive(Clone)]
99+
pub enum CompareMode {
100+
Nll
101+
}
102+
103+
impl CompareMode {
104+
fn to_str(&self) -> &'static str {
105+
match *self {
106+
CompareMode::Nll => "nll"
107+
}
108+
}
109+
}
110+
98111
#[derive(Clone)]
99112
pub struct Config {
100113
/// The library paths required for running the compiler
@@ -210,6 +223,9 @@ pub struct Config {
210223
/// where to find the remote test client process, if we're using it
211224
pub remote_test_client: Option<PathBuf>,
212225

226+
/// mode describing what file the actual ui output will be compared to
227+
pub compare_mode: Option<CompareMode>,
228+
213229
// Configuration for various run-make tests frobbing things like C compilers
214230
// or querying about various LLVM component information.
215231
pub cc: String,
@@ -230,12 +246,15 @@ pub struct TestPaths {
230246
}
231247

232248
/// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
233-
pub fn expected_output_path(testpaths: &TestPaths, revision: Option<&str>, kind: &str) -> PathBuf {
249+
pub fn expected_output_path(testpaths: &TestPaths, revision: Option<&str>, compare_mode: &Option<CompareMode>, kind: &str) -> PathBuf {
234250
assert!(UI_EXTENSIONS.contains(&kind));
235-
let extension = match revision {
236-
Some(r) => format!("{}.{}", r, kind),
237-
None => kind.to_string(),
238-
};
251+
let mut parts = Vec::new();
252+
253+
if let Some(x) = revision { parts.push(x); }
254+
if let Some(ref x) = *compare_mode { parts.push(x.to_str()); }
255+
parts.push(kind);
256+
257+
let extension = parts.join(".");
239258
testpaths.file.with_extension(extension)
240259
}
241260

src/tools/compiletest/src/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use getopts::Options;
3838
use common::{Config, TestPaths};
3939
use common::{DebugInfoGdb, DebugInfoLldb, Mode, Pretty};
4040
use common::{expected_output_path, UI_EXTENSIONS};
41+
use common::CompareMode;
4142
use test::ColorConfig;
4243
use util::logv;
4344

@@ -227,6 +228,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
227228
"path to the remote test client",
228229
"PATH",
229230
)
231+
.optopt(
232+
"",
233+
"compare-mode",
234+
"mode describing what file the actual ui output will be compared to",
235+
"COMPARE MODE"
236+
)
230237
.optflag("h", "help", "show this message");
231238

232239
let (argv0, args_) = args.split_first().unwrap();
@@ -320,6 +327,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
320327
quiet: matches.opt_present("quiet"),
321328
color,
322329
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
330+
compare_mode: matches.opt_str("compare-mode").and_then(|x| if x == "nll" { Some(CompareMode::Nll) } else { panic!("Unknown compare-mode {}", x) }),
323331

324332
cc: matches.opt_str("cc").unwrap(),
325333
cxx: matches.opt_str("cxx").unwrap(),
@@ -688,12 +696,12 @@ fn up_to_date(config: &Config, testpaths: &TestPaths, props: &EarlyProps) -> boo
688696
// UI test files.
689697
for extension in UI_EXTENSIONS {
690698
for revision in &props.revisions {
691-
let path = &expected_output_path(testpaths, Some(revision), extension);
699+
let path = &expected_output_path(testpaths, Some(revision), &config.compare_mode, extension);
692700
inputs.push(mtime(path));
693701
}
694702

695703
if props.revisions.is_empty() {
696-
let path = &expected_output_path(testpaths, None, extension);
704+
let path = &expected_output_path(testpaths, None, &config.compare_mode, extension);
697705
inputs.push(mtime(path));
698706
}
699707
}

src/tools/compiletest/src/runtest.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
1313
use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc};
1414
use common::{Incremental, MirOpt, RunMake, Ui};
1515
use common::{expected_output_path, UI_STDERR, UI_STDOUT};
16+
use common::CompareMode;
1617
use diff;
1718
use errors::{self, Error, ErrorKind};
1819
use filetime::FileTime;
@@ -1681,6 +1682,13 @@ impl<'test> TestCx<'test> {
16811682
}
16821683
}
16831684

1685+
match self.config.compare_mode {
1686+
Some(CompareMode::Nll) => {
1687+
rustc.args(&["-Znll", "-Zborrowck=mir", "-Ztwo-phase-borrows"]);
1688+
},
1689+
None => {},
1690+
}
1691+
16841692
if self.props.force_host {
16851693
rustc.args(self.split_maybe_args(&self.config.host_rustcflags));
16861694
} else {
@@ -2507,11 +2515,8 @@ impl<'test> TestCx<'test> {
25072515
let proc_res = self.compile_test();
25082516
self.check_if_test_should_compile(&proc_res);
25092517

2510-
let expected_stderr_path = self.expected_output_path(UI_STDERR);
2511-
let expected_stderr = self.load_expected_output(&expected_stderr_path);
2512-
2513-
let expected_stdout_path = self.expected_output_path(UI_STDOUT);
2514-
let expected_stdout = self.load_expected_output(&expected_stdout_path);
2518+
let expected_stderr = self.load_expected_output(UI_STDERR);
2519+
let expected_stdout = self.load_expected_output(UI_STDOUT);
25152520

25162521
let normalized_stdout =
25172522
self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout);
@@ -2797,19 +2802,31 @@ impl<'test> TestCx<'test> {
27972802
normalized
27982803
}
27992804

2800-
fn expected_output_path(&self, kind: &str) -> PathBuf {
2801-
expected_output_path(&self.testpaths, self.revision, kind)
2802-
}
2805+
fn expected_output_path(&self, kind: &str) -> Result<PathBuf, String> {
2806+
let mut path = expected_output_path(&self.testpaths, self.revision, &self.config.compare_mode, kind);
2807+
if !path.exists() && self.config.compare_mode.is_some() {
2808+
// fallback!
2809+
path = expected_output_path(&self.testpaths, self.revision, &None, kind);
2810+
}
28032811

2804-
fn load_expected_output(&self, path: &Path) -> String {
2805-
if !path.exists() {
2806-
return String::new();
2812+
if path.exists() {
2813+
Ok(path)
2814+
} else {
2815+
Err(String::from("no existing output_path found"))
28072816
}
2817+
}
28082818

2819+
fn load_expected_output(&self, kind: &str) -> String {
2820+
self.expected_output_path(kind)
2821+
.and_then(|x| self.load_expected_output_from_path(&x))
2822+
.unwrap_or_else(|x| self.fatal(&x))
2823+
}
2824+
2825+
fn load_expected_output_from_path(&self, path: &Path) -> Result<String, String> {
28092826
let mut result = String::new();
28102827
match File::open(path).and_then(|mut f| f.read_to_string(&mut result)) {
2811-
Ok(_) => result,
2812-
Err(e) => self.fatal(&format!(
2828+
Ok(_) => Ok(result),
2829+
Err(e) => Err(format!(
28132830
"failed to load expected output from `{}`: {}",
28142831
path.display(),
28152832
e

0 commit comments

Comments
 (0)