diff options
| author | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-05-16 17:18:19 +0200 |
|---|---|---|
| committer | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-05-17 16:03:59 +0200 |
| commit | 37dee69dacb0fc199d52d9baba3a3caf3018958a (patch) | |
| tree | 1fabdaecf0b46a7fe4aea47fcb50c64daeca0283 /src/tools | |
| parent | e3150564f889a3bad01795d9fcb31d4f14d58a99 (diff) | |
| download | rust-37dee69dacb0fc199d52d9baba3a3caf3018958a.tar.gz rust-37dee69dacb0fc199d52d9baba3a3caf3018958a.zip | |
Add `bless` x.py subcommand for easy ui test replacement
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/compiletest/src/common.rs | 3 | ||||
| -rw-r--r-- | src/tools/compiletest/src/main.rs | 6 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 85 |
3 files changed, 64 insertions, 30 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 812e9c5f39d..b2ce5ce52f7 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -118,6 +118,9 @@ impl CompareMode { #[derive(Clone)] pub struct Config { + /// Whether to overwrite stderr/stdout files instead of complaining about changes in output + pub bless: bool, + /// The library paths required for running the compiler pub compile_lib_path: PathBuf, diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 42a2cdfa55b..2bfc1ece095 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -168,6 +168,11 @@ pub fn parse_config(args: Vec<String>) -> Config { .optflag("", "verbose", "run tests verbosely, showing all output") .optflag( "", + "bless", + "overwrite stderr/stdout files instead of complaining about a mismatch", + ) + .optflag( + "", "quiet", "print one character per test instead of one line", ) @@ -290,6 +295,7 @@ pub fn parse_config(args: Vec<String>) -> Config { let src_base = opt_path(matches, "src-base"); let run_ignored = matches.opt_present("ignored"); Config { + bless: matches.opt_present("bless"), compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")), run_lib_path: make_absolute(opt_path(matches, "run-lib-path")), rustc_path: opt_path(matches, "rustc-path"), diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 59d94e1fa51..743d7fa93c2 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2926,29 +2926,31 @@ impl<'test> TestCx<'test> { return 0; } - if expected.is_empty() { - println!("normalized {}:\n{}\n", kind, actual); - } else { - println!("diff of {}:\n", kind); - let diff_results = make_diff(expected, actual, 3); - for result in diff_results { - let mut line_number = result.line_number; - for line in result.lines { - match line { - DiffLine::Expected(e) => { - println!("-\t{}", e); - line_number += 1; - } - DiffLine::Context(c) => { - println!("{}\t{}", line_number, c); - line_number += 1; - } - DiffLine::Resulting(r) => { - println!("+\t{}", r); + if !self.config.bless { + if expected.is_empty() { + println!("normalized {}:\n{}\n", kind, actual); + } else { + println!("diff of {}:\n", kind); + let diff_results = make_diff(expected, actual, 3); + for result in diff_results { + let mut line_number = result.line_number; + for line in result.lines { + match line { + DiffLine::Expected(e) => { + println!("-\t{}", e); + line_number += 1; + } + DiffLine::Context(c) => { + println!("{}\t{}", line_number, c); + line_number += 1; + } + DiffLine::Resulting(r) => { + println!("+\t{}", r); + } } } + println!(""); } - println!(""); } } @@ -2958,19 +2960,42 @@ impl<'test> TestCx<'test> { .with_extra_extension(mode) .with_extra_extension(kind); - match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) { - Ok(()) => {} - Err(e) => self.fatal(&format!( - "failed to write {} to `{}`: {}", - kind, - output_file.display(), - e - )), + let mut files = vec![output_file]; + if self.config.bless { + files.push(self.expected_output_path(kind)); + } + + for output_file in &files { + if actual.is_empty() { + if let Err(e) = ::std::fs::remove_file(output_file) { + self.fatal(&format!( + "failed to delete `{}`: {}", + output_file.display(), + e, + )); + } + } else { + match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) { + Ok(()) => {} + Err(e) => self.fatal(&format!( + "failed to write {} to `{}`: {}", + kind, + output_file.display(), + e + )), + } + } } println!("\nThe actual {0} differed from the expected {0}.", kind); - println!("Actual {} saved to {}", kind, output_file.display()); - 1 + for output_file in files { + println!("Actual {} saved to {}", kind, output_file.display()); + } + if self.config.bless { + 0 + } else { + 1 + } } fn create_stamp(&self) { |
