diff options
| author | memoryleak47 <memoryleak47@protonmail.ch> | 2018-03-23 03:31:43 +0100 |
|---|---|---|
| committer | memoryleak47 <memoryleak47@protonmail.ch> | 2018-03-23 03:31:43 +0100 |
| commit | 79db5fe593262611ab26c0f551190f61e3314cd8 (patch) | |
| tree | 15f72a4d73d9569a734882ee77366e6570fc9882 | |
| parent | b176285ba775f86301040fc624acb96b4499f562 (diff) | |
| download | rust-79db5fe593262611ab26c0f551190f61e3314cd8.tar.gz rust-79db5fe593262611ab26c0f551190f61e3314cd8.zip | |
add --compare-mode option to compiletest
| -rw-r--r-- | src/tools/compiletest/src/common.rs | 29 | ||||
| -rw-r--r-- | src/tools/compiletest/src/main.rs | 12 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 43 |
3 files changed, 64 insertions, 20 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 1d8cef05b7d..4a1c7b49953 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -96,6 +96,19 @@ impl fmt::Display for Mode { } #[derive(Clone)] +pub enum CompareMode { + Nll +} + +impl CompareMode { + fn to_str(&self) -> &'static str { + match *self { + CompareMode::Nll => "nll" + } + } +} + +#[derive(Clone)] pub struct Config { /// The library paths required for running the compiler pub compile_lib_path: PathBuf, @@ -210,6 +223,9 @@ pub struct Config { /// where to find the remote test client process, if we're using it pub remote_test_client: Option<PathBuf>, + /// mode describing what file the actual ui output will be compared to + pub compare_mode: Option<CompareMode>, + // Configuration for various run-make tests frobbing things like C compilers // or querying about various LLVM component information. pub cc: String, @@ -230,12 +246,15 @@ pub struct TestPaths { } /// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`. -pub fn expected_output_path(testpaths: &TestPaths, revision: Option<&str>, kind: &str) -> PathBuf { +pub fn expected_output_path(testpaths: &TestPaths, revision: Option<&str>, compare_mode: &Option<CompareMode>, kind: &str) -> PathBuf { assert!(UI_EXTENSIONS.contains(&kind)); - let extension = match revision { - Some(r) => format!("{}.{}", r, kind), - None => kind.to_string(), - }; + let mut parts = Vec::new(); + + if let Some(x) = revision { parts.push(x); } + if let Some(ref x) = *compare_mode { parts.push(x.to_str()); } + parts.push(kind); + + let extension = parts.join("."); testpaths.file.with_extension(extension) } diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index e65c03a6e57..7c676fe939d 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -38,6 +38,7 @@ use getopts::Options; use common::{Config, TestPaths}; use common::{DebugInfoGdb, DebugInfoLldb, Mode, Pretty}; use common::{expected_output_path, UI_EXTENSIONS}; +use common::CompareMode; use test::ColorConfig; use util::logv; @@ -227,6 +228,12 @@ pub fn parse_config(args: Vec<String>) -> Config { "path to the remote test client", "PATH", ) + .optopt( + "", + "compare-mode", + "mode describing what file the actual ui output will be compared to", + "COMPARE MODE" + ) .optflag("h", "help", "show this message"); let (argv0, args_) = args.split_first().unwrap(); @@ -320,6 +327,7 @@ pub fn parse_config(args: Vec<String>) -> Config { quiet: matches.opt_present("quiet"), color, remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from), + compare_mode: matches.opt_str("compare-mode").and_then(|x| if x == "nll" { Some(CompareMode::Nll) } else { panic!("Unknown compare-mode {}", x) }), cc: matches.opt_str("cc").unwrap(), cxx: matches.opt_str("cxx").unwrap(), @@ -688,12 +696,12 @@ fn up_to_date(config: &Config, testpaths: &TestPaths, props: &EarlyProps) -> boo // UI test files. for extension in UI_EXTENSIONS { for revision in &props.revisions { - let path = &expected_output_path(testpaths, Some(revision), extension); + let path = &expected_output_path(testpaths, Some(revision), &config.compare_mode, extension); inputs.push(mtime(path)); } if props.revisions.is_empty() { - let path = &expected_output_path(testpaths, None, extension); + let path = &expected_output_path(testpaths, None, &config.compare_mode, extension); inputs.push(mtime(path)); } } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 953a13a3f58..8caa5271900 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -13,6 +13,7 @@ use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind}; use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc}; use common::{Incremental, MirOpt, RunMake, Ui}; use common::{expected_output_path, UI_STDERR, UI_STDOUT}; +use common::CompareMode; use diff; use errors::{self, Error, ErrorKind}; use filetime::FileTime; @@ -1681,6 +1682,13 @@ impl<'test> TestCx<'test> { } } + match self.config.compare_mode { + Some(CompareMode::Nll) => { + rustc.args(&["-Znll", "-Zborrowck=mir", "-Ztwo-phase-borrows"]); + }, + None => {}, + } + if self.props.force_host { rustc.args(self.split_maybe_args(&self.config.host_rustcflags)); } else { @@ -2507,11 +2515,8 @@ impl<'test> TestCx<'test> { let proc_res = self.compile_test(); self.check_if_test_should_compile(&proc_res); - let expected_stderr_path = self.expected_output_path(UI_STDERR); - let expected_stderr = self.load_expected_output(&expected_stderr_path); - - let expected_stdout_path = self.expected_output_path(UI_STDOUT); - let expected_stdout = self.load_expected_output(&expected_stdout_path); + let expected_stderr = self.load_expected_output(UI_STDERR); + let expected_stdout = self.load_expected_output(UI_STDOUT); let normalized_stdout = self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout); @@ -2797,19 +2802,31 @@ impl<'test> TestCx<'test> { normalized } - fn expected_output_path(&self, kind: &str) -> PathBuf { - expected_output_path(&self.testpaths, self.revision, kind) - } + fn expected_output_path(&self, kind: &str) -> Result<PathBuf, String> { + let mut path = expected_output_path(&self.testpaths, self.revision, &self.config.compare_mode, kind); + if !path.exists() && self.config.compare_mode.is_some() { + // fallback! + path = expected_output_path(&self.testpaths, self.revision, &None, kind); + } - fn load_expected_output(&self, path: &Path) -> String { - if !path.exists() { - return String::new(); + if path.exists() { + Ok(path) + } else { + Err(String::from("no existing output_path found")) } + } + fn load_expected_output(&self, kind: &str) -> String { + self.expected_output_path(kind) + .and_then(|x| self.load_expected_output_from_path(&x)) + .unwrap_or_else(|x| self.fatal(&x)) + } + + fn load_expected_output_from_path(&self, path: &Path) -> Result<String, String> { let mut result = String::new(); match File::open(path).and_then(|mut f| f.read_to_string(&mut result)) { - Ok(_) => result, - Err(e) => self.fatal(&format!( + Ok(_) => Ok(result), + Err(e) => Err(format!( "failed to load expected output from `{}`: {}", path.display(), e |
