From c3b868bf06e1a356cef79f1b3782dd09d2b3eafe Mon Sep 17 00:00:00 2001 From: Rain Date: Mon, 25 Sep 2023 19:06:35 -0700 Subject: [PATCH] [nextest-runner] fix pluralization of cancel messages --- nextest-runner/src/reporter.rs | 38 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/nextest-runner/src/reporter.rs b/nextest-runner/src/reporter.rs index 413ca7ebcb8..aefe10aff44 100644 --- a/nextest-runner/src/reporter.rs +++ b/nextest-runner/src/reporter.rs @@ -570,17 +570,8 @@ impl<'a> TestReporterImpl<'a> { let count_style = self.styles.count; - let tests_str: &str = if test_list.run_count() == 1 { - "test" - } else { - "tests" - }; - - let binaries_str = if test_list.binary_count() == 1 { - "binary" - } else { - "binaries" - }; + let tests_str = tests_str(test_list.run_count()); + let binaries_str = binaries_str(test_list.binary_count()); write!( writer, @@ -781,27 +772,30 @@ impl<'a> TestReporterImpl<'a> { CancelReason::Signal => "signal", CancelReason::Interrupt => "interrupt", }; + let tests_str = tests_str(*running); writeln!( writer, - "due to {}: {} tests still running", + "due to {}: {} {tests_str} still running", reason_str.style(self.styles.fail), running.style(self.styles.count) )?; } TestEventKind::RunPaused { running } => { + let tests_str = tests_str(*running); writeln!( writer, - "{:>12} {} running tests due to {}", + "{:>12} {} running {tests_str} due to {}", "Pausing".style(self.styles.pass), running.style(self.styles.count), "signal".style(self.styles.count), )?; } TestEventKind::RunContinued { running } => { + let tests_str = tests_str(*running); writeln!( writer, - "{:>12} {} running tests due to {}", + "{:>12} {} running {tests_str} due to {}", "Continuing".style(self.styles.pass), running.style(self.styles.count), "signal".style(self.styles.count), @@ -1215,6 +1209,22 @@ impl<'a> TestReporterImpl<'a> { } } +fn tests_str(count: usize) -> &'static str { + if count == 1 { + "test" + } else { + "tests" + } +} + +fn binaries_str(count: usize) -> &'static str { + if count == 1 { + "binary" + } else { + "binaries" + } +} + impl<'a> fmt::Debug for TestReporter<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("TestReporter")