diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index e66094dc395..33ec974c527 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -155,5 +155,8 @@ pub struct Config { pub lldb_python_dir: Option, // Explain what's going on - pub verbose: bool + pub verbose: bool, + + // Print one character per test instead of one line + pub quiet: bool, } diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 458a3a8c739..cf467e60fe3 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -77,6 +77,7 @@ pub fn parse_config(args: Vec ) -> Config { optopt("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS"), optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS"), optflag("", "verbose", "run tests verbosely, showing all output"), + optflag("", "quiet", "print one character per test instead of one line"), optopt("", "logfile", "file to log test execution to", "FILE"), optopt("", "target", "the target to build for", "TARGET"), optopt("", "host", "the host to build for", "HOST"), @@ -151,6 +152,7 @@ pub fn parse_config(args: Vec ) -> Config { !opt_str2(matches.opt_str("adb-test-dir")).is_empty(), lldb_python_dir: matches.opt_str("lldb-python-dir"), verbose: matches.opt_present("verbose"), + quiet: matches.opt_present("quiet"), } } @@ -184,6 +186,7 @@ pub fn log_config(config: &Config) { logv(c, format!("adb_device_status: {}", config.adb_device_status)); logv(c, format!("verbose: {}", config.verbose)); + logv(c, format!("quiet: {}", config.quiet)); logv(c, format!("\n")); } @@ -247,6 +250,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts { test::TestOpts { filter: config.filter.clone(), run_ignored: config.run_ignored, + quiet: config.quiet, logfile: config.logfile.clone(), run_tests: true, bench_benchmarks: true, diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 11d2a3e65c8..d076aa2b008 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -106,7 +106,7 @@ impl fmt::Display for TestName { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq, Eq)] enum NamePadding { PadNone, PadOnRight, @@ -298,6 +298,7 @@ pub struct TestOpts { pub logfile: Option, pub nocapture: bool, pub color: ColorConfig, + pub quiet: bool, } impl TestOpts { @@ -311,6 +312,7 @@ impl TestOpts { logfile: None, nocapture: false, color: AutoColor, + quiet: false, } } } @@ -328,6 +330,7 @@ fn optgroups() -> Vec { of stdout", "PATH"), getopts::optflag("", "nocapture", "don't capture stdout/stderr of each \ task, allow printing directly"), + getopts::optflag("q", "quiet", "Display one character per test instead of one line"), getopts::optopt("", "color", "Configure coloring of output: auto = colorize if stdout is a tty and tests are run on serially (default); always = always colorize output; @@ -385,6 +388,7 @@ pub fn parse_opts(args: &[String]) -> Option { }; let run_ignored = matches.opt_present("ignored"); + let quiet = matches.opt_present("quiet"); let logfile = matches.opt_str("logfile"); let logfile = logfile.map(|s| PathBuf::from(&s)); @@ -417,6 +421,7 @@ pub fn parse_opts(args: &[String]) -> Option { logfile: logfile, nocapture: nocapture, color: color, + quiet: quiet, }; Some(Ok(test_opts)) @@ -448,6 +453,7 @@ struct ConsoleTestState { log_out: Option, out: OutputLocation, use_color: bool, + quiet: bool, total: usize, passed: usize, failed: usize, @@ -473,6 +479,7 @@ impl ConsoleTestState { out: out, log_out: log_out, use_color: use_color(opts), + quiet: opts.quiet, total: 0, passed: 0, failed: 0, @@ -485,15 +492,15 @@ impl ConsoleTestState { } 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<()> { @@ -504,6 +511,16 @@ impl ConsoleTestState { 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.quiet { + self.write_pretty(quiet, color) + } else { + try!(self.write_pretty(verbose, color)); + self.write_plain("\n") + } + } + pub fn write_pretty(&mut self, word: &str, color: term::color::Color) -> io::Result<()> { match self.out { Pretty(ref mut term) => { @@ -547,28 +564,28 @@ impl ConsoleTestState { } 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.quiet && align != PadOnRight { + Ok(()) + } else { + let name = test.padded_name(self.max_name_len, align); + self.write_plain(&format!("test {} ... ", name)) + } } 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<()> { @@ -626,9 +643,9 @@ impl ConsoleTestState { 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, @@ -755,6 +772,7 @@ fn should_sort_failures_before_printing_them() { log_out: None, out: Raw(Vec::new()), use_color: false, + quiet: false, total: 0, passed: 0, failed: 0, diff --git a/src/test/run-make/test-harness/Makefile b/src/test/run-make/test-harness/Makefile index 4517af8e24b..fc9b65c47a9 100644 --- a/src/test/run-make/test-harness/Makefile +++ b/src/test/run-make/test-harness/Makefile @@ -5,3 +5,5 @@ all: $(RUSTC) --test test-ignore-cfg.rs --cfg ignorecfg $(call RUN,test-ignore-cfg) | grep 'shouldnotignore ... ok' $(call RUN,test-ignore-cfg) | grep 'shouldignore ... ignored' + $(call RUN,test-ignore-cfg --quiet) | grep "^i\.$$" + $(call RUN,test-ignore-cfg --quiet) | grep -v 'should'