Skip to content

Commit 1eff391

Browse files
committed
Finish unit-testification of Windows update tests
One integration test kept as a smoke test for insurance.
1 parent 7050161 commit 1eff391

File tree

2 files changed

+56
-77
lines changed

2 files changed

+56
-77
lines changed

src/cli/self_update/windows.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,57 @@ mod tests {
537537
});
538538
}
539539

540+
#[test]
541+
fn windows_path_delete_key_when_empty() {
542+
use std::io;
543+
// during uninstall the PATH key may end up empty; if so we should
544+
// delete it.
545+
let tp = Box::new(currentprocess::TestProcess::default());
546+
with_registry_edits(&|| {
547+
currentprocess::with(tp.clone(), || {
548+
let root = RegKey::predef(HKEY_CURRENT_USER);
549+
let environment = root
550+
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
551+
.unwrap();
552+
environment
553+
.set_raw_value(
554+
"PATH",
555+
&RegValue {
556+
bytes: utils::string_to_winreg_bytes("foo"),
557+
vtype: RegType::REG_EXPAND_SZ,
558+
},
559+
)
560+
.unwrap();
561+
562+
assert_eq!((), super::_apply_new_path(Some("".into())).unwrap());
563+
564+
let reg_value = environment.get_raw_value("PATH");
565+
match reg_value {
566+
Ok(_) => panic!("key not deleted"),
567+
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {}
568+
Err(ref e) => panic!("error {}", e),
569+
}
570+
})
571+
});
572+
}
573+
574+
#[test]
575+
fn windows_treat_missing_path_as_empty() {
576+
// during install the PATH key may be missing; treat it as empty
577+
let tp = Box::new(currentprocess::TestProcess::default());
578+
with_registry_edits(&|| {
579+
currentprocess::with(tp.clone(), || {
580+
let root = RegKey::predef(HKEY_CURRENT_USER);
581+
let environment = root
582+
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
583+
.unwrap();
584+
environment.delete_value("PATH").unwrap();
585+
586+
assert_eq!(Some("".into()), super::get_windows_path_var().unwrap());
587+
})
588+
});
589+
}
590+
540591
#[test]
541592
fn windows_uninstall_removes_semicolon_from_path_prefix() {
542593
assert_eq!(

tests/cli-self-upd.rs

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -494,32 +494,25 @@ fn when_cargo_home_is_the_default_write_path_specially() {
494494

495495
#[test]
496496
#[cfg(windows)]
497-
fn install_adds_path() {
497+
/// Smoke test for end-to-end code connectivity of the installer path mgmt on windows.
498+
fn install_uninstall_affect_path() {
498499
setup(&|config| {
499-
expect_ok(config, &["rustup-init", "-y"]);
500-
501500
let path = config.cargodir.join("bin").to_string_lossy().to_string();
501+
502+
expect_ok(config, &["rustup-init", "-y"]);
502503
assert!(
503504
get_path().unwrap().contains(&path),
504505
format!("`{}` not in `{}`", get_path().unwrap(), &path)
505506
);
506-
});
507-
}
508507

509-
#[test]
510-
#[cfg(windows)]
511-
fn uninstall_removes_path() {
512-
setup(&|config| {
513-
expect_ok(config, &["rustup-init", "-y"]);
514508
expect_ok(config, &["rustup", "self", "uninstall", "-y"]);
515-
516-
let path = config.cargodir.join("bin").to_string_lossy().to_string();
517509
assert!(!get_path().unwrap().contains(&path));
518510
});
519511
}
520512

521513
#[test]
522514
#[cfg(unix)]
515+
/// This covers both windows and unix no-path-modification cases due to the code structure.
523516
fn install_doesnt_modify_path_if_passed_no_modify_path() {
524517
setup(&|config| {
525518
let profile = config.homedir.join(".profile");
@@ -528,31 +521,6 @@ fn install_doesnt_modify_path_if_passed_no_modify_path() {
528521
});
529522
}
530523

531-
#[test]
532-
#[cfg(windows)]
533-
fn install_doesnt_modify_path_if_passed_no_modify_path() {
534-
use winreg::enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
535-
use winreg::RegKey;
536-
537-
setup(&|config| {
538-
let root = RegKey::predef(HKEY_CURRENT_USER);
539-
let environment = root
540-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
541-
.unwrap();
542-
let old_path = environment.get_raw_value("PATH").unwrap();
543-
544-
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
545-
546-
let root = RegKey::predef(HKEY_CURRENT_USER);
547-
let environment = root
548-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
549-
.unwrap();
550-
let new_path = environment.get_raw_value("PATH").unwrap();
551-
552-
assert_eq!(old_path, new_path);
553-
});
554-
}
555-
556524
#[test]
557525
fn update_exact() {
558526
let version = env!("CARGO_PKG_VERSION");
@@ -951,10 +919,6 @@ fn produces_env_file_on_unix() {
951919
});
952920
}
953921

954-
#[test]
955-
#[cfg(windows)]
956-
fn doesnt_produce_env_file_on_windows() {}
957-
958922
#[test]
959923
fn install_sets_up_stable() {
960924
setup(&|config| {
@@ -1015,42 +979,6 @@ fn rustup_init_works_with_weird_names() {
1015979
});
1016980
}
1017981

1018-
// HKCU\Environment\PATH may not exist during install, and it may need to be
1019-
// deleted during uninstall if we remove the last path from it
1020-
#[test]
1021-
#[cfg(windows)]
1022-
fn windows_handle_empty_path_registry_key() {
1023-
use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
1024-
use winreg::RegKey;
1025-
1026-
setup(&|config| {
1027-
let root = RegKey::predef(HKEY_CURRENT_USER);
1028-
let environment = root
1029-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
1030-
.unwrap();
1031-
let _ = environment.delete_value("PATH");
1032-
1033-
expect_ok(config, &["rustup-init", "-y"]);
1034-
1035-
let root = RegKey::predef(HKEY_CURRENT_USER);
1036-
let environment = root
1037-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
1038-
.unwrap();
1039-
let path = environment.get_raw_value("PATH").unwrap();
1040-
assert!(path.vtype == RegType::REG_EXPAND_SZ);
1041-
1042-
expect_ok(config, &["rustup", "self", "uninstall", "-y"]);
1043-
1044-
let root = RegKey::predef(HKEY_CURRENT_USER);
1045-
let environment = root
1046-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
1047-
.unwrap();
1048-
let path = environment.get_raw_value("PATH");
1049-
1050-
assert!(path.is_err());
1051-
});
1052-
}
1053-
1054982
#[test]
1055983
#[ignore] // untestable
1056984
fn install_but_rustup_is_installed() {}

0 commit comments

Comments
 (0)