Skip to content

Commit 2f8c5a5

Browse files
author
Gilad Naaman
committed
libtest: Json format now outputs failed tests' stdouts.
1 parent ba06aa9 commit 2f8c5a5

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/libtest/formatters.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,26 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
325325
self.write_str(&*format!("\t\t\"filtered_out\": {}\n", state.filtered_out))?;
326326
} else {
327327
self.write_str(&*format!("\t\t\"filtered_out\": {},\n", state.filtered_out))?;
328-
self.write_str("\t\t\"failures\": [")?;
329-
330-
self.write_str("\t\t]\n")?;
328+
self.write_str("\t\t\"failures\": [\n")?;
329+
330+
let mut has_items = false;
331+
for &(ref f, ref stdout) in &state.failures {
332+
if !stdout.is_empty() {
333+
if has_items {
334+
self.write_str(",\n")?;
335+
} else {
336+
has_items = true;
337+
}
338+
339+
let output = String::from_utf8_lossy(stdout)
340+
.replace("\\", "\\\\")
341+
.replace("\"", "\\\"");
342+
343+
self.write_str(&*format!("\t\t\t\"{}\": \"{}\"", f.name, output))?;
344+
}
345+
}
346+
347+
self.write_str("\n\t\t]\n")?;
331348
}
332349

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

0 commit comments

Comments
 (0)