about summary refs log tree commit diff
path: root/src/libtest
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-11-04 02:44:54 +0800
committerkennytm <kennytm@gmail.com>2017-11-06 03:53:39 +0800
commita4e5c91cb823526765574c6d18ea6b13f1cb7dab (patch)
tree6a89fc7a53fdb63376964970cddf9ea6be0a6238 /src/libtest
parent666687a68cb9c42bf5eadcb2e5e447d7de5190d5 (diff)
downloadrust-a4e5c91cb823526765574c6d18ea6b13f1cb7dab.tar.gz
rust-a4e5c91cb823526765574c6d18ea6b13f1cb7dab.zip
libtest: Force a newline every 100 dots when testing in quiet mode.
Rationale:

We use --quiet mode when testing a PR in the CI. Also, we use `stamp` to
prefix every line with a timestamp. Previously, when testing in --quiet
mode, we will only print a dot for each test without any line breaks.
Combined with `stamp`, this means we'd need to wait for all tests to
complete before writing the output. On Travis CI, if we don't print
anything within 30 minutes, the job will be forcefully canceled. This
makes it very easy to spuriously-timeout when testing non-default images
like arm-android using the CI. This commit tries to workaround the issue
by printing a new line every 100 dots, forcing `stamp` to emit something
to reset Travis's countdown.
Diffstat (limited to 'src/libtest')
-rw-r--r--src/libtest/lib.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index e8a1242c814..76abcb83edc 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -71,6 +71,7 @@ use std::thread;
 use std::time::{Instant, Duration};
 
 const TEST_WARN_TIMEOUT_S: u64 = 60;
+const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode
 
 // to be used by rustc to compile tests in libtest
 pub mod test {
@@ -614,7 +615,14 @@ impl<T: Write> ConsoleTestState<T> {
     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)
+            self.write_pretty(quiet, color)?;
+            if self.current_test_count() % QUIET_MODE_MAX_COLUMN == QUIET_MODE_MAX_COLUMN - 1 {
+                // we insert a new line every 100 dots in order to flush the
+                // screen when dealing with line-buffered output (e.g. piping to
+                // `stamp` in the rust CI).
+                self.write_plain("\n")?;
+            }
+            Ok(())
         } else {
             self.write_pretty(verbose, color)?;
             self.write_plain("\n")
@@ -771,9 +779,12 @@ impl<T: Write> ConsoleTestState<T> {
         Ok(())
     }
 
+    fn current_test_count(&self) -> usize {
+        self.passed + self.failed + self.ignored + self.measured + self.allowed_fail
+    }
+
     pub fn write_run_finish(&mut self) -> io::Result<bool> {
-        assert!(self.passed + self.failed + self.ignored + self.measured +
-                    self.allowed_fail == self.total);
+        assert!(self.current_test_count() == self.total);
 
         if self.options.display_output {
             self.write_outputs()?;