Skip to content

Commit c4635ae

Browse files
committed
style(test): access uuid field directly
1 parent e5fe6c1 commit c4635ae

4 files changed

Lines changed: 15 additions & 19 deletions

File tree

src/cli/self_update/windows.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ fn random_uuid() -> String {
797797
/// Guards a set of registry values for the duration of a test.
798798
#[cfg(any(test, feature = "test"))]
799799
pub struct RegistryGuard {
800-
uuid: String,
800+
pub uuid: String,
801801
saved: Vec<(&'static RegistryValueId, Option<Value>)>,
802802
}
803803

@@ -814,10 +814,6 @@ impl RegistryGuard {
814814
}
815815
Ok(Self { uuid, saved })
816816
}
817-
818-
pub fn uuid(&self) -> &str {
819-
&self.uuid
820-
}
821817
}
822818

823819
#[cfg(any(test, feature = "test"))]
@@ -893,7 +889,7 @@ mod tests {
893889
("HOME".to_string(), "/unused".to_string()),
894890
(
895891
RUSTUP_TEST_REGISTRY_UUID.to_string(),
896-
guard.uuid().to_string(),
892+
guard.uuid.to_string(),
897893
),
898894
]
899895
.into_iter()
@@ -903,7 +899,7 @@ mod tests {
903899

904900
fn test_environment_key(guard: &RegistryGuard) -> Key {
905901
CURRENT_USER
906-
.create(map_sub_key("Environment", guard.uuid()))
902+
.create(map_sub_key("Environment", guard.uuid.as_str()))
907903
.unwrap()
908904
}
909905

src/test/clitools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl CliTestContext {
10001000
ids: impl IntoIterator<Item = &'static crate::cli::self_update::RegistryValueId>,
10011001
) {
10021002
let guard = crate::cli::self_update::RegistryGuard::new(ids).unwrap();
1003-
self.config.set_registry_uuid(guard.uuid());
1003+
self.config.set_registry_uuid(&guard.uuid);
10041004
self._registry_guard = Some(guard);
10051005
}
10061006

tests/suite/cli_paths.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ mod windows {
483483
async fn install_uninstall_affect_path() {
484484
let mut cx = CliTestContext::new(Scenario::Empty).await;
485485
let guard = RegistryGuard::new([&USER_PATH]).unwrap();
486-
cx.config.set_registry_uuid(guard.uuid());
487-
let uuid = guard.uuid().to_string();
486+
cx.config.set_registry_uuid(&guard.uuid);
487+
let uuid = guard.uuid.to_string();
488488
let cfg_path = cx.config.cargodir.join("bin").display().to_string();
489489
let read_path = |uuid: &str| -> Option<String> {
490490
retry(
@@ -516,8 +516,8 @@ mod windows {
516516
async fn uninstall_keeps_path_when_cargo_bin_is_non_empty() {
517517
let mut cx = CliTestContext::new(Scenario::Empty).await;
518518
let guard = RegistryGuard::new([&USER_PATH]).unwrap();
519-
cx.config.set_registry_uuid(guard.uuid());
520-
let uuid = guard.uuid().to_string();
519+
cx.config.set_registry_uuid(&guard.uuid);
520+
let uuid = guard.uuid.to_string();
521521
let cfg_path = cx.config.cargodir.join("bin").display().to_string();
522522
let get_path_ = || {
523523
HSTRING::try_from(get_path(Some(&uuid)).unwrap().unwrap())
@@ -543,8 +543,8 @@ mod windows {
543543
async fn uninstall_doesnt_affect_path_with_no_modify_path() {
544544
let mut cx = CliTestContext::new(Scenario::Empty).await;
545545
let guard = RegistryGuard::new([&USER_PATH]).unwrap();
546-
cx.config.set_registry_uuid(guard.uuid());
547-
let uuid = guard.uuid().to_string();
546+
cx.config.set_registry_uuid(&guard.uuid);
547+
let uuid = guard.uuid.to_string();
548548
let cfg_path = cx.config.cargodir.join("bin").display().to_string();
549549
let get_path_ = || {
550550
HSTRING::try_from(get_path(Some(&uuid)).unwrap().unwrap())
@@ -574,8 +574,8 @@ mod windows {
574574

575575
let mut cx = CliTestContext::new(Scenario::Empty).await;
576576
let guard = RegistryGuard::new([&USER_PATH]).unwrap();
577-
cx.config.set_registry_uuid(guard.uuid());
578-
let uuid = guard.uuid().to_string();
577+
cx.config.set_registry_uuid(&guard.uuid);
578+
let uuid = guard.uuid.to_string();
579579
// Set up a non unicode PATH
580580
let mut reg_value = Value::from([
581581
0x00, 0xD8, // leading surrogate

tests/suite/cli_self_upd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,19 @@ async fn update_overwrites_programs_display_version() {
483483

484484
let mut cx = SelfUpdateTestContext::new(TEST_VERSION).await;
485485
let guard = RegistryGuard::new([&USER_PATH, &USER_RUSTUP_VERSION]).unwrap();
486-
cx.config.set_registry_uuid(guard.uuid());
486+
cx.config.set_registry_uuid(&guard.uuid);
487487
cx.config
488488
.expect(["rustup-init", "-y", "--no-modify-path"])
489489
.await
490490
.is_ok();
491491

492492
USER_RUSTUP_VERSION
493-
.set(Some(&Value::from(PLACEHOLDER_VERSION)), Some(guard.uuid()))
493+
.set(Some(&Value::from(PLACEHOLDER_VERSION)), Some(&guard.uuid))
494494
.unwrap();
495495
cx.config.expect(["rustup", "self", "update"]).await.is_ok();
496496
assert_eq!(
497497
USER_RUSTUP_VERSION
498-
.get(Some(guard.uuid()))
498+
.get(Some(&guard.uuid))
499499
.unwrap()
500500
.unwrap(),
501501
Value::from(version)

0 commit comments

Comments
 (0)