diff --git a/crates/uv/src/commands/tool/upgrade.rs b/crates/uv/src/commands/tool/upgrade.rs index 0888039766ee..573fb933a4c5 100644 --- a/crates/uv/src/commands/tool/upgrade.rs +++ b/crates/uv/src/commands/tool/upgrade.rs @@ -178,17 +178,19 @@ pub(crate) async fn upgrade( } if let Some(python_request) = python_request { - let tools = did_upgrade_environment - .iter() - .map(|name| format!("`{}`", name.cyan())) - .collect::>(); - let s = if tools.len() > 1 { "s" } else { "" }; - writeln!( - printer.stderr(), - "Upgraded tool environment{s} for {} to {}", - conjunction(tools), - python_request.cyan(), - )?; + if !did_upgrade_environment.is_empty() { + let tools = did_upgrade_environment + .iter() + .map(|name| format!("`{}`", name.cyan())) + .collect::>(); + let s = if tools.len() > 1 { "s" } else { "" }; + writeln!( + printer.stderr(), + "Upgraded tool environment{s} for {} to {}", + conjunction(tools), + python_request.cyan(), + )?; + } } Ok(ExitStatus::Success) diff --git a/crates/uv/tests/it/tool_upgrade.rs b/crates/uv/tests/it/tool_upgrade.rs index de8bf3dc6fe6..c3f05d2ec9a6 100644 --- a/crates/uv/tests/it/tool_upgrade.rs +++ b/crates/uv/tests/it/tool_upgrade.rs @@ -5,6 +5,91 @@ use uv_static::EnvVars; use crate::common::{uv_snapshot, TestContext}; +#[test] +fn tool_upgrade_empty() { + let context = TestContext::new("3.12") + .with_filtered_counts() + .with_filtered_exe_suffix(); + let tool_dir = context.temp_dir.child("tools"); + let bin_dir = context.temp_dir.child("bin"); + + uv_snapshot!(context.filters(), context.tool_upgrade() + .arg("--all") + .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) + .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()) + .env(EnvVars::PATH, bin_dir.as_os_str()), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Nothing to upgrade + "###); + + uv_snapshot!(context.filters(), context.tool_upgrade() + .arg("--all") + .arg("-p") + .arg("3.13") + .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) + .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()) + .env(EnvVars::PATH, bin_dir.as_os_str()), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Nothing to upgrade + "###); + + // Install the latest `babel`. + uv_snapshot!(context.filters(), context.tool_install() + .arg("babel") + .arg("--index-url") + .arg("https://pypi.org/simple/") + .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) + .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()) + .env(EnvVars::PATH, bin_dir.as_os_str()), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved [N] packages in [TIME] + Prepared [N] packages in [TIME] + Installed [N] packages in [TIME] + + babel==2.14.0 + Installed 1 executable: pybabel + "###); + + uv_snapshot!(context.filters(), context.tool_upgrade() + .arg("--all") + .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) + .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()) + .env(EnvVars::PATH, bin_dir.as_os_str()), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Nothing to upgrade + "###); + + uv_snapshot!(context.filters(), context.tool_upgrade() + .arg("--all") + .arg("-p") + .arg("3.12") + .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) + .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()) + .env(EnvVars::PATH, bin_dir.as_os_str()), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Nothing to upgrade + "###); +} + #[test] fn tool_upgrade_name() { let context = TestContext::new("3.12")