Skip to content

Commit

Permalink
libtest: Json format now outputs failed tests' stdouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilad Naaman committed Dec 12, 2017
1 parent 93b0d4e commit 83569c5
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/libtest/formatters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,26 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
self.write_str(&*format!("\t\t\"filtered_out\": {}\n", state.filtered_out))?;
} else {
self.write_str(&*format!("\t\t\"filtered_out\": {},\n", state.filtered_out))?;
self.write_str("\t\t\"failures\": [")?;

self.write_str("\t\t]\n")?;
self.write_str("\t\t\"failures\": [\n")?;

let mut has_items = false;
for &(ref f, ref stdout) in &state.failures {
if !stdout.is_empty() {
if has_items {
self.write_str(",\n")?;
} else {
has_items = true;
}

let output = String::from_utf8_lossy(stdout)
.replace("\\", "\\\\")
.replace("\"", "\\\"");

self.write_str(&*format!("\t\t\t\"{}\": \"{}\"", f.name, output))?;
}
}

self.write_str("\n\t\t]\n")?;
}

self.write_str("\t}\n}\n")?;
Expand Down

0 comments on commit 83569c5

Please sign in to comment.