From 9d0818f58ea2b087fbd600705e8e2d5d7adc305f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 23 Oct 2025 10:53:46 -0500 Subject: [PATCH 1/2] test(check): Show current style --- tests/suite/cli_rustup_ui.rs | 44 +++++++++++++++++++ .../rustup_check_updates_none.stdout.term.svg | 29 ++++++++++++ .../rustup_check_updates_some.stdout.term.svg | 29 ++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg create mode 100644 tests/suite/cli_rustup_ui/rustup_check_updates_some.stdout.term.svg diff --git a/tests/suite/cli_rustup_ui.rs b/tests/suite/cli_rustup_ui.rs index 9a5c832931..d0a55dbd73 100644 --- a/tests/suite/cli_rustup_ui.rs +++ b/tests/suite/cli_rustup_ui.rs @@ -67,6 +67,50 @@ fn rustup_only_options() { test_error("rustup_only_options", &["-q"]); } +#[tokio::test] +async fn rustup_check_updates_none() { + let name = "rustup_check_updates_none"; + let cx = CliTestContext::new(Scenario::SimpleV2).await; + cx.config + .expect(["rustup", "toolchain", "add", "stable", "beta", "nightly"]) + .await + .is_ok(); + cx.config + .expect_with_env(["rustup", "check"], [("RUSTUP_TERM_COLOR", "always")]) + .await + .with_stdout(Data::read_from( + Path::new(&format!("tests/suite/cli_rustup_ui/{name}.stdout.term.svg")), + None, + )) + .with_stderr("") + .is_err(); +} + +#[tokio::test] +async fn rustup_check_updates_some() { + let name = "rustup_check_updates_some"; + let mut cx = CliTestContext::new(Scenario::None).await; + + { + let cx = cx.with_dist_dir(Scenario::ArchivesV2_2015_01_01); + cx.config + .expect(["rustup", "toolchain", "add", "stable", "beta", "nightly"]) + .await + .is_ok(); + } + + let cx = cx.with_dist_dir(Scenario::SimpleV2); + cx.config + .expect_with_env(["rustup", "check"], [("RUSTUP_TERM_COLOR", "always")]) + .await + .with_stdout(Data::read_from( + Path::new(&format!("tests/suite/cli_rustup_ui/{name}.stdout.term.svg")), + None, + )) + .with_stderr("") + .is_ok(); +} + #[test] fn rustup_check_cmd_help_flag() { test_help("rustup_check_cmd_help_flag", &["check", "--help"]); diff --git a/tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg b/tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg new file mode 100644 index 0000000000..07d9a87cde --- /dev/null +++ b/tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg @@ -0,0 +1,29 @@ + + + + + + + stable-[HOST_TRIPLE] - Up to date : 1.1.0 (hash-stable-1.1.0) + + beta-[HOST_TRIPLE] - Up to date : 1.2.0 (hash-beta-1.2.0) + + nightly-[HOST_TRIPLE] - Up to date : 1.3.0 (hash-nightly-2) + + + + + + diff --git a/tests/suite/cli_rustup_ui/rustup_check_updates_some.stdout.term.svg b/tests/suite/cli_rustup_ui/rustup_check_updates_some.stdout.term.svg new file mode 100644 index 0000000000..7165ca0c09 --- /dev/null +++ b/tests/suite/cli_rustup_ui/rustup_check_updates_some.stdout.term.svg @@ -0,0 +1,29 @@ + + + + + + + stable-[HOST_TRIPLE] - Update available : 1.0.0 (hash-stable-1.0.0) -> 1.1.0 (hash-stable-1.1.0) + + beta-[HOST_TRIPLE] - Update available : 1.1.0 (hash-beta-1.1.0) -> 1.2.0 (hash-beta-1.2.0) + + nightly-[HOST_TRIPLE] - Update available : 1.2.0 (hash-nightly-1) -> 1.3.0 (hash-nightly-2) + + + + + + From 838dcd81dfc59ec1076863972dd8683ed03c5473 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 23 Oct 2025 11:20:53 -0500 Subject: [PATCH 2/2] fix(check): Subject check to RUSTUP_TERM_COLOR `rustup check` was using `console::style` which will do its own "can I style" checks, overriding `RUSTUP_TERM_COLOR`. See https://docs.rs/console/0.16.1/src/console/utils.rs.html#696-702 --- src/cli/rustup_mode.rs | 59 +++++++++++-------- .../rustup_check_updates_none.stdout.term.svg | 8 ++- .../rustup_check_updates_some.stdout.term.svg | 8 ++- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index df833fd565..bb91e4c0a4 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -11,11 +11,11 @@ use std::{ }; use anstream::ColorChoice; +use anstyle::{AnsiColor, Style}; use anyhow::{Context, Error, Result, anyhow}; use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum, builder::PossibleValue}; use clap_cargo::style::{CONTEXT, HEADER}; use clap_complete::Shell; -use console::style; use futures_util::stream::StreamExt; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use itertools::Itertools; @@ -819,6 +819,30 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result { Some(_) | None => channels_len, }; + let bold = if use_colors { + Style::new().bold() + } else { + Style::new() + }; + + let error = if use_colors { + AnsiColor::Red.on_default().bold() + } else { + Style::new() + }; + + let good = if use_colors { + AnsiColor::Green.on_default().bold() + } else { + Style::new() + }; + + let warn = if use_colors { + AnsiColor::Yellow.on_default().bold() + } else { + Style::new() + }; + // Ensure that `.buffered()` is never called with 0 as this will cause a hang. // See: https://github.com/rust-lang/futures-rs/pull/1194#discussion_r209501774 if channels_len > 0 { @@ -842,40 +866,25 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result { let dist_version = distributable.show_dist_version().await?; let mut update_a = false; - let mut styled_name = style(format!("{name} - ")); - if use_colors { - styled_name = styled_name.bold(); - } + let styled_name = format!("{bold}{name} - {bold:#}"); let message = match (current_version, dist_version) { (None, None) => { - let mut m = style("Cannot identify installed or update versions"); - if use_colors { - m = m.red().bold(); - } - format!("{styled_name}{m}") + let m = "Cannot identify installed or update versions"; + format!("{styled_name}{error}{m}{error:#}") } (Some(cv), None) => { - let mut m = style("Up to date"); - if use_colors { - m = m.green().bold(); - } - format!("{styled_name}{m} : {cv}") + let m = "Up to date"; + format!("{styled_name}{good}{m}{good:#} : {cv}") } (Some(cv), Some(dv)) => { - let mut m = style("Update available"); - if use_colors { - m = m.yellow().bold(); - } + let m = "Update available"; update_a = true; - format!("{styled_name}{m} : {cv} -> {dv}") + format!("{styled_name}{warn}{m}{warn:#} : {cv} -> {dv}") } (None, Some(dv)) => { - let mut m = style("Update available"); - if use_colors { - m = m.yellow().bold(); - } + let m = "Update available"; update_a = true; - format!("{styled_name}{m} : (Unknown version) -> {dv}") + format!("{styled_name}{warn}{m}{warn:#} : (Unknown version) -> {dv}") } }; pb.set_style(ProgressStyle::with_template(message.as_str()).unwrap()); diff --git a/tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg b/tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg index 07d9a87cde..6a44138fe7 100644 --- a/tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg +++ b/tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg @@ -2,10 +2,12 @@