Skip to content

Commit

Permalink
Don't dump diagnostics json if not absolutely necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 2, 2019
1 parent c26f6db commit 7d4f868
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/tools/compiletest/src/json.rs
Expand Up @@ -62,19 +62,20 @@ struct DiagnosticCode {
explanation: Option<String>,
}

pub fn extract_rendered(output: &str, proc_res: &ProcRes) -> String {
pub fn extract_rendered(output: &str) -> 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!(
print!(
"failed to decode compiler output as json: \
`{}`\nline: {}\noutput: {}",
error, line, output
)));
);
panic!()
}
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/tools/compiletest/src/runtest.rs
Expand Up @@ -2760,7 +2760,7 @@ impl<'test> TestCx<'test> {
let stderr = if explicit {
proc_res.stderr.clone()
} else {
json::extract_rendered(&proc_res.stderr, &proc_res)
json::extract_rendered(&proc_res.stderr)
};

let normalized_stderr = self.normalize_output(&stderr, &self.props.normalize_stderr);
Expand Down Expand Up @@ -3377,7 +3377,9 @@ impl ProcRes {
{}\n\
------------------------------------------\n\
\n",
self.status, self.cmdline, self.stdout, self.stderr
self.status, self.cmdline,
json::extract_rendered(&self.stdout),
json::extract_rendered(&self.stderr),
);
panic!();
}
Expand Down

0 comments on commit 7d4f868

Please sign in to comment.