Skip to content

Commit 336d255

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

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

src/libtest/formatters.rs

+36-10
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<T: Write> HumanFormatter<T> {
7777
// `stamp` in the rust CI).
7878
self.write_plain("\n")?;
7979
}
80-
80+
8181
self.test_count += 1;
8282
Ok(())
8383
} else {
@@ -296,13 +296,39 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
296296

297297
fn write_result(&mut self, desc: &TestDesc, result: &TestResult) -> io::Result<()> {
298298
let output = match *result {
299-
TrOk => format!("\t\t{{ \"test\": \"{}\", \"event\": \"ok\" }}", desc.name),
300-
TrFailed => format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\" }}", desc.name),
301-
TrFailedMsg(ref m) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\", \"extra\": \"{}\" }}", desc.name, m),
302-
TrIgnored => format!("\t\t{{ \"test\": \"{}\", \"event\": \"ignored\" }}", desc.name),
303-
TrAllowedFail => format!("\t\t{{ \"test\": \"{}\", \"event\": \"allowed_failure\" }}", desc.name),
304-
TrMetrics(ref mm) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"metrics\", \"extra\": \"{}\" }}", desc.name, mm.fmt_metrics()),
305-
TrBench(ref bs) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"bench\", \"extra\": \"{}\" }}", desc.name, fmt_bench_samples(bs)),
299+
TrOk => {
300+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"ok\" }}", desc.name)
301+
},
302+
303+
TrFailed => {
304+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\" }}", desc.name)
305+
},
306+
307+
TrFailedMsg(ref m) => {
308+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\", \"extra\": \"{}\" }}",
309+
desc.name,
310+
m)
311+
},
312+
313+
TrIgnored => {
314+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"ignored\" }}", desc.name)
315+
},
316+
317+
TrAllowedFail => {
318+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"allowed_failure\" }}", desc.name)
319+
},
320+
321+
TrMetrics(ref mm) => {
322+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"metrics\", \"extra\": \"{}\" }}",
323+
desc.name,
324+
mm.fmt_metrics())
325+
},
326+
327+
TrBench(ref bs) => {
328+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"bench\", \"extra\": \"{}\" }}",
329+
desc.name,
330+
fmt_bench_samples(bs))
331+
},
306332
};
307333

308334
self.write_event(&*output)
@@ -343,10 +369,10 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
343369
self.write_str(&*format!("\t\t\t\"{}\": \"{}\"", f.name, output))?;
344370
}
345371
}
346-
372+
347373
self.write_str("\n\t\t]\n")?;
348374
}
349-
375+
350376
self.write_str("\t}\n}\n")?;
351377

352378
Ok(state.failed == 0)

src/libtest/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl TestOpts {
374374
logfile: None,
375375
nocapture: false,
376376
color: AutoColor,
377-
format: OutputFormat,
377+
format: OutputFormat::Pretty,
378378
test_threads: None,
379379
skip: vec![],
380380
options: Options::new(),
@@ -400,8 +400,8 @@ fn optgroups() -> getopts::Options {
400400
in parallel", "n_threads")
401401
.optmulti("", "skip", "Skip tests whose names contain FILTER (this flag can \
402402
be used multiple times)","FILTER")
403-
.optflag("q", "quiet", "Display one character per test instead of one line.\
404-
Equivalent to --format=terse")
403+
.optflag("q", "quiet", "Display one character per test instead of one line. \
404+
Alias to --format=terse")
405405
.optflag("", "exact", "Exactly match filters rather than by substring")
406406
.optopt("", "color", "Configure coloring of output:
407407
auto = colorize if stdout is a tty and tests are run on serially (default);
@@ -697,7 +697,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
697697
None => Raw(io::stdout()),
698698
Some(t) => Pretty(t),
699699
};
700-
700+
701701
let quiet = opts.format == OutputFormat::Terse;
702702
let mut out = HumanFormatter::new(output, use_color(opts), quiet);
703703
let mut st = ConsoleTestState::new(opts)?;

0 commit comments

Comments
 (0)