Skip to content

Commit e3a9adc

Browse files
committed
Shorter output for rustc --test binaries.
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.
1 parent 1fe384b commit e3a9adc

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustc-test"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
authors = ["The Rust Project Developers"]
55
license = "MIT OR Apache-2.0"
66
description = "A fork of Rust’s `test` crate that doesn’t require unstable language features."

src/lib.rs

+34-17
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl fmt::Display for TestName {
102102
}
103103
}
104104

105-
#[derive(Clone, Copy)]
105+
#[derive(Clone, Copy, PartialEq, Eq)]
106106
enum NamePadding {
107107
PadNone,
108108
PadOnRight,
@@ -301,6 +301,7 @@ pub struct TestOpts {
301301
pub logfile: Option<PathBuf>,
302302
pub nocapture: bool,
303303
pub color: ColorConfig,
304+
pub verbose: bool,
304305
}
305306

306307
impl TestOpts {
@@ -314,6 +315,7 @@ impl TestOpts {
314315
logfile: None,
315316
nocapture: false,
316317
color: AutoColor,
318+
verbose: false,
317319
}
318320
}
319321
}
@@ -337,7 +339,8 @@ fn options() -> getopts::Options {
337339
opts.optopt("", "color", "Configure coloring of output:
338340
auto = colorize if stdout is a tty and tests are run on serially (default);
339341
always = always colorize output;
340-
never = never colorize output;", "auto|always|never");
342+
never = never colorize output;", "auto|always|never")
343+
.optflag("v", "verbose", "Display the name of each test when it starts");
341344
opts
342345
}
343346

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

399402
let run_ignored = matches.opt_present("ignored");
403+
let verbose = matches.opt_present("verbose");
400404

401405
let logfile = matches.opt_str("logfile");
402406
let logfile = logfile.map(|s| PathBuf::from(&s));
@@ -430,6 +434,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
430434
logfile: logfile,
431435
nocapture: nocapture,
432436
color: color,
437+
verbose: verbose,
433438
};
434439

435440
Some(Ok(test_opts))
@@ -461,6 +466,7 @@ struct ConsoleTestState<T> {
461466
log_out: Option<File>,
462467
out: OutputLocation<T>,
463468
use_color: bool,
469+
verbose: bool,
464470
total: usize,
465471
passed: usize,
466472
failed: usize,
@@ -486,6 +492,7 @@ impl<T: Write> ConsoleTestState<T> {
486492
out: out,
487493
log_out: log_out,
488494
use_color: use_color(opts),
495+
verbose: opts.verbose,
489496
total: 0,
490497
passed: 0,
491498
failed: 0,
@@ -498,15 +505,15 @@ impl<T: Write> ConsoleTestState<T> {
498505
}
499506

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

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

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

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

527+
pub fn write_short_result(&mut self, verbose: &str, quiet: &str, color: term::color::Color)
528+
-> io::Result<()> {
529+
if self.verbose {
530+
try!(self.write_pretty(verbose, color));
531+
self.write_plain("\n")
532+
} else {
533+
self.write_pretty(quiet, color)
534+
}
535+
}
536+
520537
pub fn write_pretty(&mut self, word: &str, color: term::color::Color) -> io::Result<()> {
521538
match self.out {
522539
Pretty(ref mut term) => {
@@ -560,28 +577,28 @@ impl<T: Write> ConsoleTestState<T> {
560577
}
561578

562579
pub fn write_test_start(&mut self, test: &TestDesc, align: NamePadding) -> io::Result<()> {
563-
let name = test.padded_name(self.max_name_len, align);
564-
self.write_plain(&format!("test {} ... ", name))
580+
if self.verbose || align == PadOnRight {
581+
let name = test.padded_name(self.max_name_len, align);
582+
self.write_plain(&format!("test {} ... ", name))
583+
} else {
584+
Ok(())
585+
}
565586
}
566587

567588
pub fn write_result(&mut self, result: &TestResult) -> io::Result<()> {
568-
try!(match *result {
589+
match *result {
569590
TrOk => self.write_ok(),
570591
TrFailed => self.write_failed(),
571592
TrIgnored => self.write_ignored(),
572593
TrMetrics(ref mm) => {
573594
try!(self.write_metric());
574-
self.write_plain(&format!(": {}", mm.fmt_metrics()))
595+
self.write_plain(&format!(": {}\n", mm.fmt_metrics()))
575596
}
576597
TrBench(ref bs) => {
577598
try!(self.write_bench());
578-
579-
try!(self.write_plain(&format!(": {}", fmt_bench_samples(bs))));
580-
581-
Ok(())
599+
self.write_plain(&format!(": {}\n", fmt_bench_samples(bs)))
582600
}
583-
});
584-
self.write_plain("\n")
601+
}
585602
}
586603

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

0 commit comments

Comments
 (0)