diff --git a/src/cli/self_update/test.rs b/src/cli/self_update/test.rs index 2426df7086d..c0142ae0e30 100644 --- a/src/cli/self_update/test.rs +++ b/src/cli/self_update/test.rs @@ -10,18 +10,15 @@ use winreg::{ }; #[cfg(not(unix))] -pub fn get_path() -> Option { +pub fn get_path() -> std::io::Result> { let root = RegKey::predef(HKEY_CURRENT_USER); let environment = root .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); match environment.get_raw_value("PATH") { - Ok(val) => Some(val), - Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => None, - Err(e) => panic!( - "Error getting PATH: {}\nBetter abort to avoid trashing it.", - e - ), + Ok(val) => Ok(Some(val)), + Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None), + Err(e) => Err(e), } } @@ -48,15 +45,15 @@ pub fn with_saved_path(f: &dyn Fn()) { // On windows these tests mess with the user's PATH. Save // and restore them here to keep from trashing things. - let saved_path = get_path(); + let saved_path = get_path().expect("Error getting PATH: Better abort to avoid trashing it."); let _g = scopeguard::guard(saved_path, restore_path); f(); } #[cfg(unix)] -pub fn get_path() -> Option<()> { - None +pub fn get_path() -> Result> { + Ok(None) } #[cfg(unix)] diff --git a/tests/cli-paths.rs b/tests/cli-paths.rs index 2212b77b865..686d4c1a760 100644 --- a/tests/cli-paths.rs +++ b/tests/cli-paths.rs @@ -318,14 +318,15 @@ mod windows { expect_ok(config, &INIT_NONE); assert!( get_path() + .unwrap() .unwrap() .to_string() .contains(path.trim_matches('"')), - format!("`{}` not in `{}`", path, get_path().unwrap()) + format!("`{}` not in `{}`", path, get_path().unwrap().unwrap()) ); expect_ok(config, &["rustup", "self", "uninstall", "-y"]); - assert!(!get_path().unwrap().to_string().contains(&path)); + assert!(!get_path().unwrap().unwrap().to_string().contains(&path)); }) }); } @@ -367,10 +368,10 @@ mod windows { }; expect_ok(config, &INIT_NONE); - assert_eq!(get_path().unwrap(), expected); + assert_eq!(get_path().unwrap().unwrap(), expected); expect_ok(config, &["rustup", "self", "uninstall", "-y"]); - assert_eq!(get_path().unwrap(), reg_value); + assert_eq!(get_path().unwrap().unwrap(), reg_value); }) }); }