From b170fdd4b6061360bc5a3e330a424b661835291f Mon Sep 17 00:00:00 2001 From: red Date: Sat, 2 Mar 2024 05:57:06 +0100 Subject: [PATCH] [nextest-runner] add option hide-progress-bar to configuration file --- cargo-nextest/src/dispatch.rs | 5 ++++- nextest-runner/default-config.toml | 4 ++++ nextest-runner/src/config/config_impl.rs | 13 +++++++++++++ nextest-runner/src/reporter.rs | 13 +++++++------ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/cargo-nextest/src/dispatch.rs b/cargo-nextest/src/dispatch.rs index bf3573a1553..f27213309a6 100644 --- a/cargo-nextest/src/dispatch.rs +++ b/cargo-nextest/src/dispatch.rs @@ -878,7 +878,10 @@ impl TestReporterOpts { if let Some(final_status_level) = self.final_status_level { builder.set_final_status_level(final_status_level.into()); } - builder.set_hide_progress_bar(self.hide_progress_bar); + match self.hide_progress_bar { + true => builder.set_hide_progress_bar(Some(true)), + false => builder.set_hide_progress_bar(None), + }; builder } } diff --git a/nextest-runner/default-config.toml b/nextest-runner/default-config.toml index 0398ca41ba9..9187c6e046a 100644 --- a/nextest-runner/default-config.toml +++ b/nextest-runner/default-config.toml @@ -67,6 +67,10 @@ success-output = "never" # to false. fail-fast = true +# Hide the progress bar when running tests. For CI runs, consider setting this +# to true +hide-progress-bar = false + # Treat a test that takes longer than the configured 'period' as slow, and print a message. # See for more information. # diff --git a/nextest-runner/src/config/config_impl.rs b/nextest-runner/src/config/config_impl.rs index b8496beac94..02975dd2322 100644 --- a/nextest-runner/src/config/config_impl.rs +++ b/nextest-runner/src/config/config_impl.rs @@ -702,6 +702,13 @@ impl<'cfg> NextestProfile<'cfg, FinalConfig> { .unwrap_or(self.default_profile.fail_fast) } + /// Returns the hide-progress-bar config for this profile. + pub fn hide_progress_bar(&self) -> bool { + self.custom_profile + .and_then(|profile| profile.hide_progress_bar) + .unwrap_or(self.default_profile.hide_progress_bar) + } + /// Returns the list of setup scripts. pub fn setup_scripts(&self, test_list: &TestList<'_>) -> SetupScripts<'_> { SetupScripts::new(self, test_list) @@ -880,6 +887,7 @@ pub(super) struct DefaultProfileImpl { failure_output: TestOutputDisplay, success_output: TestOutputDisplay, fail_fast: bool, + hide_progress_bar: bool, slow_timeout: SlowTimeout, leak_timeout: Duration, overrides: Vec, @@ -910,6 +918,9 @@ impl DefaultProfileImpl { .success_output .expect("success-output present in default profile"), fail_fast: p.fail_fast.expect("fail-fast present in default profile"), + hide_progress_bar: p + .hide_progress_bar + .expect("hide-progress-bar present in default profile"), slow_timeout: p .slow_timeout .expect("slow-timeout present in default profile"), @@ -972,6 +983,8 @@ pub(super) struct CustomProfileImpl { success_output: Option, #[serde(default)] fail_fast: Option, + #[serde(default)] + hide_progress_bar: Option, #[serde(default, deserialize_with = "super::deserialize_slow_timeout")] slow_timeout: Option, #[serde(default, with = "humantime_serde::option")] diff --git a/nextest-runner/src/reporter.rs b/nextest-runner/src/reporter.rs index 3283ff17dc9..4068f78d1c6 100644 --- a/nextest-runner/src/reporter.rs +++ b/nextest-runner/src/reporter.rs @@ -168,9 +168,8 @@ pub struct TestReporterBuilder { success_output: Option, status_level: Option, final_status_level: Option, - verbose: bool, - hide_progress_bar: bool, + hide_progress_bar: Option, } impl TestReporterBuilder { @@ -215,7 +214,7 @@ impl TestReporterBuilder { /// Sets visibility of the progress bar. /// The progress bar is also hidden if `no_capture` is set. - pub fn set_hide_progress_bar(&mut self, hide_progress_bar: bool) -> &mut Self { + pub fn set_hide_progress_bar(&mut self, hide_progress_bar: Option) -> &mut Self { self.hide_progress_bar = hide_progress_bar; self } @@ -250,6 +249,10 @@ impl TestReporterBuilder { .final_status_level .unwrap_or_else(|| profile.final_status_level()); + let hide_progress_bar = self + .hide_progress_bar + .unwrap_or_else(|| profile.hide_progress_bar()); + // failure_output and success_output are meaningless if the runner isn't capturing any // output. let force_success_output = match self.no_capture { @@ -278,9 +281,7 @@ impl TestReporterBuilder { // in these environments. ReporterStderrImpl::TerminalWithoutBar } - ReporterStderr::Terminal if self.hide_progress_bar => { - ReporterStderrImpl::TerminalWithoutBar - } + ReporterStderr::Terminal if hide_progress_bar => ReporterStderrImpl::TerminalWithoutBar, ReporterStderr::Terminal => { let progress_bar = ProgressBar::new(test_list.test_count() as u64);