Skip to content

Commit ba9102d

Browse files
authored
[nextest-runner] make --show-progress=running an alias for bar (#2741)
Also display running tests by default, capped to `max_running_progress` -- and allow setting this to 0 for behavior identical to current versions of nextest.
1 parent 88ec58c commit ba9102d

File tree

3 files changed

+24
-42
lines changed

3 files changed

+24
-42
lines changed

cargo-nextest/src/dispatch/cli.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,9 @@ pub(super) struct ReporterOpts {
878878
///
879879
/// When more tests are running than this limit, the progress bar will show
880880
/// the first N tests and a summary of remaining tests (e.g. "... and 24
881-
/// more tests running"). Set to **infinite** for unlimited. This only
882-
/// applies when using `--show-progress=running` or `only`.
881+
/// more tests running"). Set to **0** to hide running tests, or
882+
/// **infinite** for unlimited. This applies when using
883+
/// `--show-progress=bar` or `--show-progress=only`.
883884
#[arg(
884885
long = "max-progress-running",
885886
value_name = "N",
@@ -1074,16 +1075,15 @@ enum ShowProgressOpt {
10741075
/// Do not display a progress bar or counter.
10751076
None,
10761077

1077-
/// Display a progress bar: default for interactive terminals.
1078+
/// Display a progress bar with running tests: default for interactive
1079+
/// terminals.
1080+
#[clap(alias = "running")]
10781081
Bar,
10791082

10801083
/// Display a counter next to each completed test.
10811084
Counter,
10821085

1083-
/// Display each running test on a separate line.
1084-
Running,
1085-
1086-
/// Display each running test on a separate line, and hide successful test
1086+
/// Display a progress bar with running tests, and hide successful test
10871087
/// output; equivalent to `--show-progress=running --status-level=slow
10881088
/// --final-status-level=none`.
10891089
Only,
@@ -1094,9 +1094,8 @@ impl From<ShowProgressOpt> for ShowProgress {
10941094
match opt {
10951095
ShowProgressOpt::Auto => ShowProgress::Auto,
10961096
ShowProgressOpt::None => ShowProgress::None,
1097-
ShowProgressOpt::Bar => ShowProgress::Bar,
1097+
ShowProgressOpt::Bar => ShowProgress::Running,
10981098
ShowProgressOpt::Counter => ShowProgress::Counter,
1099-
ShowProgressOpt::Running => ShowProgress::Running,
11001099
ShowProgressOpt::Only => ShowProgress::Running,
11011100
}
11021101
}

nextest-runner/src/reporter/displayer/imp.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl DisplayReporterBuilder {
123123

124124
let show_counter = match self.show_progress {
125125
ShowProgress::Auto => is_ci::uncached() || !show_progress_bar,
126-
ShowProgress::Bar | ShowProgress::Running | ShowProgress::None => false,
126+
ShowProgress::Running | ShowProgress::None => false,
127127
ShowProgress::Counter => true,
128128
};
129129
let counter_width = show_counter.then_some(usize_decimal_char_width(self.test_count));
@@ -180,23 +180,14 @@ impl DisplayReporterBuilder {
180180
return None;
181181
}
182182

183-
let show_running = match self.show_progress {
184-
ShowProgress::None | ShowProgress::Counter => return None,
185-
// For auto we enable progress bar if not in CI and not a terminal.
186-
// Both of these conditions are checked above.
187-
ShowProgress::Auto | ShowProgress::Bar => false,
188-
ShowProgress::Running => true,
189-
};
190-
191-
let state = ProgressBarState::new(
192-
self.test_count,
193-
progress_chars,
194-
show_running,
195-
max_progress_running,
196-
);
197-
// Note: even if we create a progress bar here, if stderr is
198-
// piped, indicatif will not show it.
199-
Some(state)
183+
match self.show_progress {
184+
ShowProgress::None | ShowProgress::Counter => None,
185+
ShowProgress::Auto | ShowProgress::Running => {
186+
let state =
187+
ProgressBarState::new(self.test_count, progress_chars, max_progress_running);
188+
Some(state)
189+
}
190+
}
200191
}
201192
}
202193

nextest-runner/src/reporter/displayer/progress.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::{
1818
cmp::{max, min},
1919
env, fmt,
2020
io::IsTerminal,
21-
num::NonZero,
2221
str::FromStr,
2322
time::{Duration, Instant},
2423
};
@@ -43,15 +42,16 @@ const PROGRESS_REFRESH_RATE_HZ: u8 = 1;
4342
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4443
pub enum MaxProgressRunning {
4544
/// Show a specific maximum number of running tests.
46-
Count(NonZero<usize>),
45+
/// If 0, running tests (including the overflow summary) aren't displayed.
46+
Count(usize),
4747

4848
/// Show all running tests (no limit).
4949
Infinite,
5050
}
5151

5252
impl MaxProgressRunning {
5353
/// The default value (8 tests).
54-
pub const DEFAULT_VALUE: Self = Self::Count(NonZero::new(8).unwrap());
54+
pub const DEFAULT_VALUE: Self = Self::Count(8);
5555
}
5656

5757
impl Default for MaxProgressRunning {
@@ -70,12 +70,7 @@ impl FromStr for MaxProgressRunning {
7070

7171
match s.parse::<usize>() {
7272
Err(e) => Err(format!("Error: {e} parsing {s}")),
73-
Ok(0) => Err(
74-
"max-progress-running may not be 0 (use \"infinite\" for unlimited)".to_string(),
75-
),
76-
Ok(n) => Ok(Self::Count(
77-
NonZero::new(n).expect("we just checked that this isn't 0"),
78-
)),
73+
Ok(n) => Ok(Self::Count(n)),
7974
}
8075
}
8176
}
@@ -99,9 +94,6 @@ pub enum ShowProgress {
9994
/// No progress display.
10095
None,
10196

102-
/// Show a progress bar.
103-
Bar,
104-
10597
/// Show a counter on each line.
10698
Counter,
10799

@@ -195,7 +187,6 @@ impl ProgressBarState {
195187
pub(super) fn new(
196188
test_count: usize,
197189
progress_chars: &str,
198-
show_running: bool,
199190
max_progress_running: MaxProgressRunning,
200191
) -> Self {
201192
let bar = ProgressBar::new(test_count as u64);
@@ -215,7 +206,8 @@ impl ProgressBarState {
215206
.expect("template is known to be valid"),
216207
);
217208

218-
let running_tests = show_running.then(Vec::new);
209+
let running_tests =
210+
(!matches!(max_progress_running, MaxProgressRunning::Count(0))).then(Vec::new);
219211

220212
// The println chunk size defaults to a value chosen by experimentation,
221213
// locally and over SSH. This controls how often the progress bar
@@ -287,7 +279,7 @@ impl ProgressBarState {
287279
let width = max(width as usize, 40);
288280
let now = Instant::now();
289281
let mut count = match self.max_progress_running {
290-
MaxProgressRunning::Count(count) => min(running_tests.len(), count.into()),
282+
MaxProgressRunning::Count(count) => min(running_tests.len(), count),
291283
MaxProgressRunning::Infinite => running_tests.len(),
292284
};
293285
for running_test in &running_tests[..count] {

0 commit comments

Comments
 (0)