Skip to content

Commit

Permalink
test(self-update): ensure the resolution of #3739
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Apr 15, 2024
1 parent 0678d7f commit 65858d8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub use crate::cli::self_update::test::{get_path, with_saved_path};
use crate::currentprocess;
use crate::dist::dist::TargetTriple;

#[cfg(windows)]
pub use crate::cli::self_update::test::with_saved_programs_display_version;

// Things that can have environment variables applied to them.
pub trait Env {
fn env<K, V>(&mut self, key: K, val: V)
Expand Down
39 changes: 38 additions & 1 deletion tests/suite/cli_self_upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use rustup::utils::{raw, utils};
use rustup::{for_host, DUP_TOOLS, TOOLS};
use rustup_macros::integration_test as test;

#[cfg(windows)]
use rustup::test::with_saved_programs_display_version;

const TEST_VERSION: &str = "1.1.1";

pub fn update_setup(f: &dyn Fn(&mut Config, &Path)) {
Expand Down Expand Up @@ -304,7 +307,41 @@ info: downloading self-update
&["rustup", "self", "update"],
&format!(" rustup updated - {version} (from {version})\n\n",),
&expected_output,
)
);
});
}

#[test]
#[cfg(windows)]
fn update_overwrites_programs_display_version() {
const RUSTUP_UNINSTALL_ENTRY: &str =
r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Rustup";

const PLACEHOLDER_VERSION: &str = "9.999.99";
let version = env!("CARGO_PKG_VERSION");

update_setup(&|config, _| {
with_saved_programs_display_version(&mut || {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);

winreg::RegKey::predef(winreg::enums::HKEY_CURRENT_USER)
.create_subkey(RUSTUP_UNINSTALL_ENTRY)
.unwrap()
.0
.set_value("DisplayVersion", &PLACEHOLDER_VERSION)
.unwrap();

config.expect_ok(&["rustup", "self", "update"]);

assert_eq!(
winreg::RegKey::predef(winreg::enums::HKEY_CURRENT_USER)
.open_subkey(RUSTUP_UNINSTALL_ENTRY)
.unwrap()
.get_value::<String, _>("DisplayVersion")
.unwrap(),
version,
);
});
});
}

Expand Down

0 comments on commit 65858d8

Please sign in to comment.