diff options
Diffstat (limited to 'cli/tools/test.rs')
-rw-r--r-- | cli/tools/test.rs | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs index b6e9e3d70..7e673fac4 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -5,6 +5,7 @@ use crate::cache::CacherLoader; use crate::colors; use crate::compat; use crate::create_main_worker; +use crate::display; use crate::emit; use crate::file_fetcher::File; use crate::file_watcher; @@ -269,7 +270,11 @@ impl PrettyTestReporter { print!("{}", " ".repeat(description.level)); } - println!("{} {}", status, colors::gray(human_elapsed(elapsed.into()))); + println!( + "{} {}", + status, + colors::gray(format!("({})", display::human_elapsed(elapsed.into()))) + ); if let Some(error_text) = result.error() { for line in error_text.lines() { @@ -279,22 +284,6 @@ impl PrettyTestReporter { } } -/// A function that converts a milisecond elapsed time to a string that -/// represents a human readable version of that time. -fn human_elapsed(elapsed: u128) -> String { - if elapsed < 1_000 { - return format!("({}ms)", elapsed); - } - if elapsed < 1_000 * 60 { - return format!("({}s)", elapsed / 1000); - } - - let seconds = elapsed / 1_000; - let minutes = seconds / 60; - let seconds_remainder = seconds % 60; - format!("({}m{}s)", minutes, seconds_remainder) -} - impl TestReporter for PrettyTestReporter { fn report_plan(&mut self, plan: &TestPlan) { let inflection = if plan.total == 1 { "test" } else { "tests" }; @@ -355,7 +344,11 @@ impl TestReporter for PrettyTestReporter { print!(" "); } - println!("{} {}", status, colors::gray(human_elapsed(elapsed.into()))); + println!( + "{} {}", + status, + colors::gray(format!("({})", display::human_elapsed(elapsed.into()))) + ); } fn report_step_wait(&mut self, description: &TestStepDescription) { @@ -432,7 +425,8 @@ impl TestReporter for PrettyTestReporter { get_steps_text(summary.ignored_steps), summary.measured, summary.filtered_out, - colors::gray(human_elapsed(elapsed.as_millis())), + colors::gray( + format!("({})", display::human_elapsed(elapsed.as_millis()))), ); } } @@ -1303,19 +1297,3 @@ pub async fn run_tests_with_watch( Ok(()) } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_human_elapsed() { - assert_eq!(human_elapsed(1), "(1ms)"); - assert_eq!(human_elapsed(256), "(256ms)"); - assert_eq!(human_elapsed(1000), "(1s)"); - assert_eq!(human_elapsed(1001), "(1s)"); - assert_eq!(human_elapsed(1020), "(1s)"); - assert_eq!(human_elapsed(70 * 1000), "(1m10s)"); - assert_eq!(human_elapsed(86 * 1000 + 100), "(1m26s)"); - } -} |