Skip to content

Commit

Permalink
Shorter output for rustc --test binaries.
Browse files Browse the repository at this point in the history
Until now, a program created with `rustc --test` prints at least one line per
test. This can be very verbose, especially with [data-driven tests](
https://internals.rust-lang.org/t/test-and-external-test-harnesses/3145)
when hundreds or thousands of tests is not rare.

This changes the default output to one character per test (except metrics
and benchmarks results which have additional data to show):

```
     Running target/debug/wpt-75c594dc1e6e6187

running 314 tests
..............................................................................
..............................................................................
..............................................................................
..............................................................................
..
test result: ok. 314 passed; 0 failed; 0 ignored; 0 measured
```

The previous behavior is available by passing `--verbose` to the test program.
  • Loading branch information
SimonSapin committed Feb 25, 2016
1 parent 1fe384b commit e3a9adc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustc-test"
version = "0.1.2"
version = "0.1.3"
authors = ["The Rust Project Developers"]
license = "MIT OR Apache-2.0"
description = "A fork of Rust’s `test` crate that doesn’t require unstable language features."
Expand Down
51 changes: 34 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl fmt::Display for TestName {
}
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq)]
enum NamePadding {
PadNone,
PadOnRight,
Expand Down Expand Up @@ -301,6 +301,7 @@ pub struct TestOpts {
pub logfile: Option<PathBuf>,
pub nocapture: bool,
pub color: ColorConfig,
pub verbose: bool,
}

impl TestOpts {
Expand All @@ -314,6 +315,7 @@ impl TestOpts {
logfile: None,
nocapture: false,
color: AutoColor,
verbose: false,
}
}
}
Expand All @@ -337,7 +339,8 @@ fn options() -> getopts::Options {
opts.optopt("", "color", "Configure coloring of output:
auto = colorize if stdout is a tty and tests are run on serially (default);
always = always colorize output;
never = never colorize output;", "auto|always|never");
never = never colorize output;", "auto|always|never")
.optflag("v", "verbose", "Display the name of each test when it starts");
opts
}

Expand Down Expand Up @@ -397,6 +400,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
};

let run_ignored = matches.opt_present("ignored");
let verbose = matches.opt_present("verbose");

let logfile = matches.opt_str("logfile");
let logfile = logfile.map(|s| PathBuf::from(&s));
Expand Down Expand Up @@ -430,6 +434,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
logfile: logfile,
nocapture: nocapture,
color: color,
verbose: verbose,
};

Some(Ok(test_opts))
Expand Down Expand Up @@ -461,6 +466,7 @@ struct ConsoleTestState<T> {
log_out: Option<File>,
out: OutputLocation<T>,
use_color: bool,
verbose: bool,
total: usize,
passed: usize,
failed: usize,
Expand All @@ -486,6 +492,7 @@ impl<T: Write> ConsoleTestState<T> {
out: out,
log_out: log_out,
use_color: use_color(opts),
verbose: opts.verbose,
total: 0,
passed: 0,
failed: 0,
Expand All @@ -498,15 +505,15 @@ impl<T: Write> ConsoleTestState<T> {
}

pub fn write_ok(&mut self) -> io::Result<()> {
self.write_pretty("ok", term::color::GREEN)
self.write_short_result("ok", ".", term::color::GREEN)
}

pub fn write_failed(&mut self) -> io::Result<()> {
self.write_pretty("FAILED", term::color::RED)
self.write_short_result("FAILED", "F", term::color::RED)
}

pub fn write_ignored(&mut self) -> io::Result<()> {
self.write_pretty("ignored", term::color::YELLOW)
self.write_short_result("ignored", "i", term::color::YELLOW)
}

pub fn write_metric(&mut self) -> io::Result<()> {
Expand All @@ -517,6 +524,16 @@ impl<T: Write> ConsoleTestState<T> {
self.write_pretty("bench", term::color::CYAN)
}

pub fn write_short_result(&mut self, verbose: &str, quiet: &str, color: term::color::Color)
-> io::Result<()> {
if self.verbose {
try!(self.write_pretty(verbose, color));
self.write_plain("\n")
} else {
self.write_pretty(quiet, color)
}
}

pub fn write_pretty(&mut self, word: &str, color: term::color::Color) -> io::Result<()> {
match self.out {
Pretty(ref mut term) => {
Expand Down Expand Up @@ -560,28 +577,28 @@ impl<T: Write> ConsoleTestState<T> {
}

pub fn write_test_start(&mut self, test: &TestDesc, align: NamePadding) -> io::Result<()> {
let name = test.padded_name(self.max_name_len, align);
self.write_plain(&format!("test {} ... ", name))
if self.verbose || align == PadOnRight {
let name = test.padded_name(self.max_name_len, align);
self.write_plain(&format!("test {} ... ", name))
} else {
Ok(())
}
}

pub fn write_result(&mut self, result: &TestResult) -> io::Result<()> {
try!(match *result {
match *result {
TrOk => self.write_ok(),
TrFailed => self.write_failed(),
TrIgnored => self.write_ignored(),
TrMetrics(ref mm) => {
try!(self.write_metric());
self.write_plain(&format!(": {}", mm.fmt_metrics()))
self.write_plain(&format!(": {}\n", mm.fmt_metrics()))
}
TrBench(ref bs) => {
try!(self.write_bench());

try!(self.write_plain(&format!(": {}", fmt_bench_samples(bs))));

Ok(())
self.write_plain(&format!(": {}\n", fmt_bench_samples(bs)))
}
});
self.write_plain("\n")
}
}

pub fn write_log(&mut self, test: &TestDesc, result: &TestResult) -> io::Result<()> {
Expand Down Expand Up @@ -639,9 +656,9 @@ impl<T: Write> ConsoleTestState<T> {
try!(self.write_plain("\ntest result: "));
if success {
// There's no parallelism at this point so it's safe to use color
try!(self.write_ok());
try!(self.write_pretty("ok", term::color::GREEN));
} else {
try!(self.write_failed());
try!(self.write_pretty("FAILED", term::color::RED));
}
let s = format!(". {} passed; {} failed; {} ignored; {} measured\n\n",
self.passed,
Expand Down

0 comments on commit e3a9adc

Please sign in to comment.