From 4069dd1eed1edc89c393f83e3c6f5da8cc918ac4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 23 Oct 2025 10:26:16 -0500 Subject: [PATCH 1/4] test(toolchain): Show list's behavior --- tests/suite/cli_rustup_ui.rs | 26 ++++++++++++++++++ .../rustup_toolchain_list.stdout.term.svg | 27 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg diff --git a/tests/suite/cli_rustup_ui.rs b/tests/suite/cli_rustup_ui.rs index 506e262294..7cc3e80a0b 100644 --- a/tests/suite/cli_rustup_ui.rs +++ b/tests/suite/cli_rustup_ui.rs @@ -405,6 +405,32 @@ fn rustup_toolchain_cmd_link_cmd_help_flag() { ); } +#[tokio::test] +async fn rustup_toolchain_list() { + let name = "rustup_toolchain_list"; + let cx = CliTestContext::new(Scenario::ArchivesV2).await; + cx.config + .expect(["rustup", "update", "nightly"]) + .await + .is_ok(); + cx.config + .expect(["rustup", "update", "beta-2015-01-01"]) + .await + .is_ok(); + cx.config + .expect_with_env( + ["rustup", "toolchain", "list"], + [("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_toolchain_cmd_list_cmd_help_flag() { test_help( diff --git a/tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg b/tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg new file mode 100644 index 0000000000..4bbf1d6db0 --- /dev/null +++ b/tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg @@ -0,0 +1,27 @@ + + + + + + + beta-2015-01-01-[HOST_TRIPLE] + + nightly-[HOST_TRIPLE] (active, default) + + + + + + From 1b2b3a38a414705483c937e393386e6b191ecee9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 23 Oct 2025 10:27:40 -0500 Subject: [PATCH 2/4] refactor(toolchain): Use string interpolation --- src/cli/common.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cli/common.rs b/src/cli/common.rs index c3c652ef25..e10028c950 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -327,10 +327,7 @@ pub(crate) async fn list_toolchains( writeln!( cfg.process.stdout().lock(), - "{}{}{}", - &toolchain, - status_str, - toolchain_path + "{toolchain}{status_str}{toolchain_path}", )?; Ok(()) } From ec41955f99171e8fe74c1d5f5f620cfde79d41d3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 23 Oct 2025 10:28:16 -0500 Subject: [PATCH 3/4] refactor(toolchain): Order logic by display order --- src/cli/common.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cli/common.rs b/src/cli/common.rs index e10028c950..3eeb70be85 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -307,6 +307,13 @@ pub(crate) async fn list_toolchains( return Ok(()); } + let status_str = match (is_default, is_active) { + (true, true) => " (active, default)", + (true, false) => " (default)", + (false, true) => " (active)", + (false, false) => "", + }; + let toolchain_path = cfg.toolchains_dir.join(toolchain); let toolchain_meta = fs::symlink_metadata(&toolchain_path)?; let toolchain_path = if verbose { @@ -318,12 +325,6 @@ pub(crate) async fn list_toolchains( } else { String::new() }; - let status_str = match (is_default, is_active) { - (true, true) => " (active, default)", - (true, false) => " (default)", - (false, true) => " (active)", - (false, false) => "", - }; writeln!( cfg.process.stdout().lock(), From d0f76d54c2424bb450df77e914ea9c8d04ef54f1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 23 Oct 2025 10:29:27 -0500 Subject: [PATCH 4/4] fix(toolchain): Have 'list' match 'show's styling `rustup show` and `rustup toolchain list` have similar lists but the latter was unstyled. This updates it to be styled to match `rustup show` as of #4556. Maybe there would be a way to single source this in the future. They do handle paths differently, so it would likely require a larger conversation. --- src/cli/common.rs | 4 ++-- .../suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cli/common.rs b/src/cli/common.rs index 3eeb70be85..37acedf153 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -9,7 +9,7 @@ use std::{cmp, env}; use anstyle::Style; use anyhow::{Context, Result, anyhow}; -use clap_cargo::style::{ERROR, UPDATE_ADDED, UPDATE_UNCHANGED, UPDATE_UPGRADED}; +use clap_cargo::style::{CONTEXT, ERROR, UPDATE_ADDED, UPDATE_UNCHANGED, UPDATE_UPGRADED}; use git_testament::{git_testament, render_testament}; use tracing::{error, info, warn}; use tracing_subscriber::{EnvFilter, Registry, reload::Handle}; @@ -328,7 +328,7 @@ pub(crate) async fn list_toolchains( writeln!( cfg.process.stdout().lock(), - "{toolchain}{status_str}{toolchain_path}", + "{toolchain}{CONTEXT}{status_str}{CONTEXT:#}{toolchain_path}", )?; Ok(()) } diff --git a/tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg b/tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg index 4bbf1d6db0..47d2427515 100644 --- a/tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg +++ b/tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg @@ -2,10 +2,12 @@