Skip to content

Commit 36dacde

Browse files
committed
libtest: Print the names of failed tests eagerly
Previously, libtest would wait until all tests finished running to print the progress, which made it annoying to run many tests at once (since you don't know which have failed). Change it to print the names as soon as they fail.
1 parent 33156aa commit 36dacde

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

library/test/src/formatters/terse.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ impl<T: Write> TerseFormatter<T> {
4747
self.write_short_result(".", term::color::GREEN)
4848
}
4949

50-
pub fn write_failed(&mut self) -> io::Result<()> {
51-
self.write_short_result("F", term::color::RED)
50+
pub fn write_failed(&mut self, name: &str) -> io::Result<()> {
51+
// Put failed tests on their own line and include the test name, so that it's faster
52+
// to see which test failed without having to wait for them all to run.
53+
self.write_plain(format!("\n{name} --- "))?;
54+
self.write_pretty("F", term::color::RED)?;
55+
self.write_progress()
5256
}
5357

5458
pub fn write_ignored(&mut self) -> io::Result<()> {
@@ -65,15 +69,21 @@ impl<T: Write> TerseFormatter<T> {
6569
color: term::color::Color,
6670
) -> io::Result<()> {
6771
self.write_pretty(result, color)?;
68-
if self.test_column % QUIET_MODE_MAX_COLUMN == QUIET_MODE_MAX_COLUMN - 1 {
72+
self.test_column += 1;
73+
if self.test_column == QUIET_MODE_MAX_COLUMN {
6974
// We insert a new line regularly in order to flush the
7075
// screen when dealing with line-buffered output (e.g., piping to
7176
// `stamp` in the rust CI).
72-
let out = format!(" {}/{}\n", self.test_column + 1, self.total_test_count);
73-
self.write_plain(out)?;
77+
self.write_progress()?;
7478
}
7579

76-
self.test_column += 1;
80+
Ok(())
81+
}
82+
83+
fn write_progress(&mut self) -> io::Result<()> {
84+
let out = format!(" {}/{}\n", self.test_column, self.total_test_count);
85+
self.write_plain(out)?;
86+
self.test_column = 0;
7787
Ok(())
7888
}
7989

@@ -213,7 +223,7 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
213223
match *result {
214224
TestResult::TrOk => self.write_ok(),
215225
TestResult::TrFailed | TestResult::TrFailedMsg(_) | TestResult::TrTimedFail => {
216-
self.write_failed()
226+
self.write_failed(desc.name.as_slice())
217227
}
218228
TestResult::TrIgnored => self.write_ignored(),
219229
TestResult::TrBench(ref bs) => {

tests/ui/test-attrs/terse.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile-flags: --test
2+
// run-fail
3+
// run-flags: --test-threads=1 --quiet
4+
// check-run-results
5+
// exec-env:RUST_BACKTRACE=0
6+
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
7+
// ignore-emscripten no threads support
8+
// needs-unwind
9+
10+
mod test {
11+
#[test]
12+
fn foo() {
13+
panic!();
14+
}
15+
16+
#[test]
17+
fn bar() {}
18+
#[test]
19+
fn baz() {}
20+
}

tests/ui/test-attrs/terse.run.stdout

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
running 3 tests
3+
..
4+
test::foo --- F 2/3
5+
6+
failures:
7+
8+
---- test::foo stdout ----
9+
thread 'test::foo' panicked at $DIR/terse.rs:13:9:
10+
explicit panic
11+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
12+
13+
14+
failures:
15+
test::foo
16+
17+
test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
18+

0 commit comments

Comments
 (0)