From d1835b418f1bc261d6f81f6f31ffa3f137b4908c Mon Sep 17 00:00:00 2001 From: Leedehai <18319900+Leedehai@users.noreply.github.com> Date: Wed, 6 Dec 2023 05:02:08 -0500 Subject: [PATCH] Use a rotating test progress printer (#2872) --- tests/src/tests.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/src/tests.rs b/tests/src/tests.rs index 82876e6cc..d7722ce66 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -4,7 +4,7 @@ use std::cell::{RefCell, RefMut}; use std::collections::{HashMap, HashSet}; use std::ffi::OsStr; use std::fmt::{self, Display, Formatter, Write as _}; -use std::io::{self, Write}; +use std::io::{self, IsTerminal, Write}; use std::ops::Range; use std::path::{Path, PathBuf}; use std::{env, fs}; @@ -135,8 +135,10 @@ fn main() { let len = results.len(); let ok = results.iter().sum::(); - if len > 1 { - println!("{ok} / {len} tests passed."); + if len > 0 { + println!("{ok} / {len} test{} passed.", if len > 1 { "s" } else { "" }); + } else { + println!("No test ran."); } if ok != len { @@ -475,6 +477,10 @@ fn test( stdout.write_all(name.to_string_lossy().as_bytes()).unwrap(); if ok { writeln!(stdout, " ✔").unwrap(); + if stdout.is_terminal() { + // ANSI escape codes: cursor moves up and clears the line. + write!(stdout, "\x1b[1A\x1b[2K").unwrap(); + } } else { writeln!(stdout, " ❌").unwrap(); }