diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-11-20 12:49:03 +0100 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-11-24 08:06:43 +0100 |
| commit | 36066d8925940cdd423886a2eec2a096363f5bb8 (patch) | |
| tree | ad8bf6a96e066abbd128f99d8480b7095279deaf | |
| parent | f7361a887005ea351a3ceabba8548fdec6ee27ff (diff) | |
| download | rust-36066d8925940cdd423886a2eec2a096363f5bb8.tar.gz rust-36066d8925940cdd423886a2eec2a096363f5bb8.zip | |
UI tests extract the regular output from the 'rendered' field in json
| -rw-r--r-- | src/tools/compiletest/src/json.rs | 19 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 37 |
2 files changed, 48 insertions, 8 deletions
diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 8e9cd1a12fa..99d7dc78166 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -57,6 +57,25 @@ struct DiagnosticCode { explanation: Option<String>, } +pub fn extract_rendered(output: &str, proc_res: &ProcRes) -> String { + output.lines() + .filter_map(|line| if line.starts_with('{') { + match json::decode::<Diagnostic>(line) { + Ok(diagnostic) => diagnostic.rendered, + Err(error) => { + proc_res.fatal(Some(&format!("failed to decode compiler output as json: \ + `{}`\noutput: {}\nline: {}", + error, + line, + output))); + } + } + } else { + None + }) + .collect() +} + pub fn parse_output(file_name: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> { output.lines() .flat_map(|line| parse_line(file_name, line, output, proc_res)) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 73ed77a6887..bb7c3616f2a 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1403,6 +1403,11 @@ actual:\n\ rustc.args(&["--error-format", "json"]); } } + Ui => { + if !self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")) { + rustc.args(&["--error-format", "json"]); + } + } MirOpt => { rustc.args(&[ "-Zdump-mir=all", @@ -1427,7 +1432,6 @@ actual:\n\ Codegen | Rustdoc | RunMake | - Ui | CodegenUnits => { // do not use JSON output } @@ -2211,7 +2215,12 @@ actual:\n\ } fn run_ui_test(&self) { - let proc_res = self.compile_test(); + // if the user specified a format in the ui test + // print the output to the stderr file, otherwise extract + // the rendered error messages from json and print them + let explicit = self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")); + + let mut proc_res = self.compile_test(); let expected_stderr_path = self.expected_output_path("stderr"); let expected_stderr = self.load_expected_output(&expected_stderr_path); @@ -2220,14 +2229,24 @@ actual:\n\ let expected_stdout = self.load_expected_output(&expected_stdout_path); let normalized_stdout = - self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout); + self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout, explicit); + + let stderr = if explicit { + proc_res.stderr.clone() + } else { + json::extract_rendered(&proc_res.stderr, &proc_res) + }; + let normalized_stderr = - self.normalize_output(&proc_res.stderr, &self.props.normalize_stderr); + self.normalize_output(&stderr, &self.props.normalize_stderr, explicit); let mut errors = 0; errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout); errors += self.compare_output("stderr", &normalized_stderr, &expected_stderr); + // rewrite the output to the human readable one (shown in case of errors) + proc_res.stderr = normalized_stderr; + if errors > 0 { println!("To update references, run this command from build directory:"); let relative_path_to_file = @@ -2421,11 +2440,13 @@ actual:\n\ mir_dump_dir } - fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> String { + fn normalize_output( + &self, + output: &str, + custom_rules: &[(String, String)], + json: bool, + ) -> String { let parent_dir = self.testpaths.file.parent().unwrap(); - let cflags = self.props.compile_flags.join(" "); - let json = cflags.contains("--error-format json") || - cflags.contains("--error-format pretty-json"); let parent_dir_str = if json { parent_dir.display().to_string().replace("\\", "\\\\") } else { |
