From a7cd4244b22e899c4438034bf36a761d8c84f823 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Thu, 17 Sep 2026 15:32:55 +0200 Subject: [PATCH] test: hide progress spinners in test runs Steady-tick spinner threads redraw straight to the real stderr, bypassing both the harness capture and the per-test log files: 'Scaffolding' lines from the pkh new tests kept leaking between test results. The scaffold tests now pass a hidden draw target (the only MultiProgress not created by the CLI). --- src/new/mod.rs | 7 ++++++- src/ui.rs | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/new/mod.rs b/src/new/mod.rs index f90bea7..b14c0ca 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -331,7 +331,12 @@ mod tests { ) -> Result> { let previous = std::env::current_dir()?; std::env::set_current_dir(dir)?; - let result = scaffold(opts, &MultiProgress::new()); + // Hidden draw target: in tests the spinner would redraw from its + // steady-tick thread straight to the real stderr + let result = scaffold( + opts, + &MultiProgress::with_draw_target(crate::ui::progress_draw_target()), + ); std::env::set_current_dir(previous)?; result } diff --git a/src/ui.rs b/src/ui.rs index 63a6de3..54052da 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -9,7 +9,11 @@ pub mod logfmt; /// yes/no confirmation pub mod prompt; -use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; +use indicatif::{ + MultiProgress, ProgressBar, ProgressStyle, +}; +#[cfg(test)] +use indicatif::ProgressDrawTarget; use std::path::Path; use std::time::Duration; @@ -38,6 +42,16 @@ pub(crate) fn spinner_style() -> ProgressStyle { .unwrap() } +/// Progress draw target for a [`MultiProgress`]: hidden in test runs +/// +/// Steady-tick spinners redraw from a background thread straight to the real +/// stderr, bypassing both the test harness capture and the per-test log +/// files; in tests there is no terminal to animate anyway. +#[cfg(test)] +pub(crate) fn progress_draw_target() -> ProgressDrawTarget { + ProgressDrawTarget::hidden() +} + /// Style of a sized transfer: prefix on the first line, the bar on its own /// indented line below so long prefixes cannot push it out of the terminal pub(crate) fn transfer_style() -> ProgressStyle {