diff --git a/src/cli/common.rs b/src/cli/common.rs index c3c652ef25..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}; @@ -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,19 +325,10 @@ 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(), - "{}{}{}", - &toolchain, - status_str, - toolchain_path + "{toolchain}{CONTEXT}{status_str}{CONTEXT:#}{toolchain_path}", )?; Ok(()) } 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..47d2427515 --- /dev/null +++ b/tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg @@ -0,0 +1,29 @@ + + + + + + + beta-2015-01-01-[HOST_TRIPLE] + + nightly-[HOST_TRIPLE] (active, default) + + + + + +