diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-02-28 16:17:44 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-03-14 00:52:17 +0100 |
| commit | 8c75e18e5d23ea88914a8e276037980e96866c76 (patch) | |
| tree | fcac2bc7c09146cebc73746ce915bb1319580ed8 /src/tools | |
| parent | c29085761b0bf5b9add4bd008268651feae495bd (diff) | |
| download | rust-8c75e18e5d23ea88914a8e276037980e96866c76.tar.gz rust-8c75e18e5d23ea88914a8e276037980e96866c76.zip | |
test for putting back check on json
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/compiletest/src/json.rs | 20 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 43 |
2 files changed, 43 insertions, 20 deletions
diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 08630628b71..761d1e511d5 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -24,6 +24,7 @@ struct Diagnostic { level: String, spans: Vec<DiagnosticSpan>, children: Vec<Diagnostic>, + rendered: Option<String>, } #[derive(Deserialize, Clone)] @@ -56,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 serde_json::from_str::<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 6619838cce0..953a13a3f58 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -248,7 +248,7 @@ impl<'test> TestCx<'test> { } fn run_cfail_test(&self) { - let proc_res = self.compile_test(&[]); + let proc_res = self.compile_test(); self.check_if_test_should_compile(&proc_res); self.check_no_compiler_crash(&proc_res); @@ -267,7 +267,7 @@ impl<'test> TestCx<'test> { } fn run_rfail_test(&self) { - let proc_res = self.compile_test(&[]); + let proc_res = self.compile_test(); if !proc_res.status.success() { self.fatal_proc_rec("compilation failed!", &proc_res); @@ -309,7 +309,7 @@ impl<'test> TestCx<'test> { } fn run_rpass_test(&self) { - let proc_res = self.compile_test(&[]); + let proc_res = self.compile_test(); if !proc_res.status.success() { self.fatal_proc_rec("compilation failed!", &proc_res); @@ -336,7 +336,7 @@ impl<'test> TestCx<'test> { return self.run_rpass_test(); } - let mut proc_res = self.compile_test(&[]); + let mut proc_res = self.compile_test(); if !proc_res.status.success() { self.fatal_proc_rec("compilation failed!", &proc_res); @@ -578,7 +578,7 @@ impl<'test> TestCx<'test> { let mut cmds = commands.join("\n"); // compile test file (it should have 'compile-flags:-g' in the header) - let compiler_run_result = self.compile_test(&[]); + let compiler_run_result = self.compile_test(); if !compiler_run_result.status.success() { self.fatal_proc_rec("compilation failed!", &compiler_run_result); } @@ -835,7 +835,7 @@ impl<'test> TestCx<'test> { fn run_debuginfo_lldb_test_no_opt(&self) { // compile test file (it should have 'compile-flags:-g' in the header) - let compile_result = self.compile_test(&[]); + let compile_result = self.compile_test(); if !compile_result.status.success() { self.fatal_proc_rec("compilation failed!", &compile_result); } @@ -1272,15 +1272,12 @@ impl<'test> TestCx<'test> { } } - fn compile_test(&self, extra_args: &[&'static str]) -> ProcRes { + fn compile_test(&self) -> ProcRes { let mut rustc = self.make_compile_args( &self.testpaths.file, TargetLocation::ThisFile(self.make_exe_name()), ); - if !extra_args.is_empty() { - rustc.args(extra_args); - } rustc.arg("-L").arg(&self.aux_output_dir_name()); match self.config.mode { @@ -1626,12 +1623,14 @@ impl<'test> TestCx<'test> { if self.props.error_patterns.is_empty() { rustc.args(&["--error-format", "json"]); } + if !self.props.disable_ui_testing_normalization { + rustc.arg("-Zui-testing"); + } } Ui => { - // In case no "--error-format" has been given in the test, we'll compile - // a first time to get the compiler's output then compile with - // "--error-format json" to check if all expected errors are actually there - // and that no new one appeared. + if !self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")) { + rustc.args(&["--error-format", "json"]); + } if !self.props.disable_ui_testing_normalization { rustc.arg("-Zui-testing"); } @@ -2114,7 +2113,7 @@ impl<'test> TestCx<'test> { fn run_codegen_units_test(&self) { assert!(self.revision.is_none(), "revisions not relevant here"); - let proc_res = self.compile_test(&[]); + let proc_res = self.compile_test(); if !proc_res.status.success() { self.fatal_proc_rec("compilation failed!", &proc_res); @@ -2505,7 +2504,7 @@ impl<'test> TestCx<'test> { .iter() .any(|s| s.contains("--error-format")); - let proc_res = self.compile_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); @@ -2517,8 +2516,13 @@ impl<'test> TestCx<'test> { let normalized_stdout = self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout); - let normalized_stderr = self.normalize_output(&proc_res.stderr, - &self.props.normalize_stderr); + let stderr = if explicit { + proc_res.stderr.clone() + } else { + json::extract_rendered(&proc_res.stderr, &proc_res) + }; + + let normalized_stderr = self.normalize_output(&stderr, &self.props.normalize_stderr); let mut errors = 0; errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout); @@ -2551,7 +2555,6 @@ impl<'test> TestCx<'test> { } } if !explicit { - let proc_res = self.compile_test(&["--error-format", "json"]); if !expected_errors.is_empty() || !proc_res.status.success() { // "// error-pattern" comments self.check_expected_errors(expected_errors, &proc_res); @@ -2563,7 +2566,7 @@ impl<'test> TestCx<'test> { } fn run_mir_opt_test(&self) { - let proc_res = self.compile_test(&[]); + let proc_res = self.compile_test(); if !proc_res.status.success() { self.fatal_proc_rec("compilation failed!", &proc_res); |
