Skip to content

Commit 83569c5

Browse files
author
Gilad Naaman
committed
libtest: Json format now outputs failed tests' stdouts.
1 parent 93b0d4e commit 83569c5

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/libtest/formatters.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,26 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
317317
self.write_str(&*format!("\t\t\"filtered_out\": {}\n", state.filtered_out))?;
318318
} else {
319319
self.write_str(&*format!("\t\t\"filtered_out\": {},\n", state.filtered_out))?;
320-
self.write_str("\t\t\"failures\": [")?;
321-
322-
self.write_str("\t\t]\n")?;
320+
self.write_str("\t\t\"failures\": [\n")?;
321+
322+
let mut has_items = false;
323+
for &(ref f, ref stdout) in &state.failures {
324+
if !stdout.is_empty() {
325+
if has_items {
326+
self.write_str(",\n")?;
327+
} else {
328+
has_items = true;
329+
}
330+
331+
let output = String::from_utf8_lossy(stdout)
332+
.replace("\\", "\\\\")
333+
.replace("\"", "\\\"");
334+
335+
self.write_str(&*format!("\t\t\t\"{}\": \"{}\"", f.name, output))?;
336+
}
337+
}
338+
339+
self.write_str("\n\t\t]\n")?;
323340
}
324341

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

0 commit comments

Comments
 (0)