Skip to content

Commit 6b97816

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

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
@@ -73,7 +73,7 @@ impl<T: Write> HumanFormatter<T> {
7373
// `stamp` in the rust CI).
7474
self.write_plain("\n")?;
7575
}
76-
76+
7777
self.test_count += 1;
7878
Ok(())
7979
} else {
@@ -288,13 +288,39 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
288288

289289
fn write_result(&mut self, desc: &TestDesc, result: &TestResult) -> io::Result<()> {
290290
let output = match *result {
291-
TrOk => format!("\t\t{{ \"test\": \"{}\", \"event\": \"ok\" }}", desc.name),
292-
TrFailed => format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\" }}", desc.name),
293-
TrFailedMsg(ref m) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\", \"extra\": \"{}\" }}", desc.name, m),
294-
TrIgnored => format!("\t\t{{ \"test\": \"{}\", \"event\": \"ignored\" }}", desc.name),
295-
TrAllowedFail => format!("\t\t{{ \"test\": \"{}\", \"event\": \"allowed_failure\" }}", desc.name),
296-
TrMetrics(ref mm) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"metrics\", \"extra\": \"{}\" }}", desc.name, mm.fmt_metrics()),
297-
TrBench(ref bs) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"bench\", \"extra\": \"{}\" }}", desc.name, fmt_bench_samples(bs)),
291+
TrOk => {
292+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"ok\" }}", desc.name)
293+
},
294+
295+
TrFailed => {
296+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\" }}", desc.name)
297+
},
298+
299+
TrFailedMsg(ref m) => {
300+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\", \"extra\": \"{}\" }}",
301+
desc.name,
302+
m)
303+
},
304+
305+
TrIgnored => {
306+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"ignored\" }}", desc.name)
307+
},
308+
309+
TrAllowedFail => {
310+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"allowed_failure\" }}", desc.name)
311+
},
312+
313+
TrMetrics(ref mm) => {
314+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"metrics\", \"extra\": \"{}\" }}",
315+
desc.name,
316+
mm.fmt_metrics())
317+
},
318+
319+
TrBench(ref bs) => {
320+
format!("\t\t{{ \"test\": \"{}\", \"event\": \"bench\", \"extra\": \"{}\" }}",
321+
desc.name,
322+
fmt_bench_samples(bs))
323+
},
298324
};
299325

300326
self.write_event(&*output)
@@ -335,10 +361,10 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
335361
self.write_str(&*format!("\t\t\t\"{}\": \"{}\"", f.name, output))?;
336362
}
337363
}
338-
364+
339365
self.write_str("\n\t\t]\n")?;
340366
}
341-
367+
342368
self.write_str("\t}\n}\n")?;
343369

344370
Ok(state.failed == 0)

src/libtest/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl TestOpts {
358358
logfile: None,
359359
nocapture: false,
360360
color: AutoColor,
361-
format: OutputFormat,
361+
format: OutputFormat::Pretty,
362362
test_threads: None,
363363
skip: vec![],
364364
options: Options::new(),
@@ -384,8 +384,8 @@ fn optgroups() -> getopts::Options {
384384
in parallel", "n_threads")
385385
.optmulti("", "skip", "Skip tests whose names contain FILTER (this flag can \
386386
be used multiple times)","FILTER")
387-
.optflag("q", "quiet", "Display one character per test instead of one line.\
388-
Equivalent to --format=terse")
387+
.optflag("q", "quiet", "Display one character per test instead of one line. \
388+
Alias to --format=terse")
389389
.optflag("", "exact", "Exactly match filters rather than by substring")
390390
.optopt("", "color", "Configure coloring of output:
391391
auto = colorize if stdout is a tty and tests are run on serially (default);
@@ -680,7 +680,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
680680
None => Raw(io::stdout()),
681681
Some(t) => Pretty(t),
682682
};
683-
683+
684684
let quiet = opts.format == OutputFormat::Terse;
685685
let mut out = HumanFormatter::new(output, use_color(opts), quiet);
686686
let mut st = ConsoleTestState::new(opts)?;

0 commit comments

Comments
 (0)