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 83569c5 commit 6b97816
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
46 changes: 36 additions & 10 deletions src/libtest/formatters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<T: Write> HumanFormatter<T> {
// `stamp` in the rust CI).
self.write_plain("\n")?;
}

self.test_count += 1;
Ok(())
} else {
Expand Down Expand Up @@ -288,13 +288,39 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {

fn write_result(&mut self, desc: &TestDesc, result: &TestResult) -> io::Result<()> {
let output = match *result {
TrOk => format!("\t\t{{ \"test\": \"{}\", \"event\": \"ok\" }}", desc.name),
TrFailed => format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\" }}", desc.name),
TrFailedMsg(ref m) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\", \"extra\": \"{}\" }}", desc.name, m),
TrIgnored => format!("\t\t{{ \"test\": \"{}\", \"event\": \"ignored\" }}", desc.name),
TrAllowedFail => format!("\t\t{{ \"test\": \"{}\", \"event\": \"allowed_failure\" }}", desc.name),
TrMetrics(ref mm) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"metrics\", \"extra\": \"{}\" }}", desc.name, mm.fmt_metrics()),
TrBench(ref bs) => format!("\t\t{{ \"test\": \"{}\", \"event\": \"bench\", \"extra\": \"{}\" }}", desc.name, fmt_bench_samples(bs)),
TrOk => {
format!("\t\t{{ \"test\": \"{}\", \"event\": \"ok\" }}", desc.name)
},

TrFailed => {
format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\" }}", desc.name)
},

TrFailedMsg(ref m) => {
format!("\t\t{{ \"test\": \"{}\", \"event\": \"failed\", \"extra\": \"{}\" }}",
desc.name,
m)
},

TrIgnored => {
format!("\t\t{{ \"test\": \"{}\", \"event\": \"ignored\" }}", desc.name)
},

TrAllowedFail => {
format!("\t\t{{ \"test\": \"{}\", \"event\": \"allowed_failure\" }}", desc.name)
},

TrMetrics(ref mm) => {
format!("\t\t{{ \"test\": \"{}\", \"event\": \"metrics\", \"extra\": \"{}\" }}",
desc.name,
mm.fmt_metrics())
},

TrBench(ref bs) => {
format!("\t\t{{ \"test\": \"{}\", \"event\": \"bench\", \"extra\": \"{}\" }}",
desc.name,
fmt_bench_samples(bs))
},
};

self.write_event(&*output)
Expand Down Expand Up @@ -335,10 +361,10 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
self.write_str(&*format!("\t\t\t\"{}\": \"{}\"", f.name, output))?;
}
}

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

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

Ok(state.failed == 0)
Expand Down
8 changes: 4 additions & 4 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl TestOpts {
logfile: None,
nocapture: false,
color: AutoColor,
format: OutputFormat,
format: OutputFormat::Pretty,
test_threads: None,
skip: vec![],
options: Options::new(),
Expand All @@ -384,8 +384,8 @@ fn optgroups() -> getopts::Options {
in parallel", "n_threads")
.optmulti("", "skip", "Skip tests whose names contain FILTER (this flag can \
be used multiple times)","FILTER")
.optflag("q", "quiet", "Display one character per test instead of one line.\
Equivalent to --format=terse")
.optflag("q", "quiet", "Display one character per test instead of one line. \
Alias to --format=terse")
.optflag("", "exact", "Exactly match filters rather than by substring")
.optopt("", "color", "Configure coloring of output:
auto = colorize if stdout is a tty and tests are run on serially (default);
Expand Down Expand Up @@ -680,7 +680,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
None => Raw(io::stdout()),
Some(t) => Pretty(t),
};

let quiet = opts.format == OutputFormat::Terse;
let mut out = HumanFormatter::new(output, use_color(opts), quiet);
let mut st = ConsoleTestState::new(opts)?;
Expand Down

0 comments on commit 6b97816

Please sign in to comment.