Skip to content

Commit 9ce7461

Browse files
cyqsimonrami3l
authored andcommitted
cli: add tests for rustup self uninstall --no-modify-path
1 parent 1a45f9a commit 9ce7461

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/suite/cli_paths.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,49 @@ error: could not amend shell profile[..]
266266
}
267267
}
268268

269+
#[tokio::test]
270+
async fn uninstall_doesnt_modify_rcs_with_no_modify_path() {
271+
let cx = CliTestContext::new(Scenario::Empty).await;
272+
let rcs = [
273+
".bashrc",
274+
".bash_profile",
275+
".bash_login",
276+
".profile",
277+
// This requires zsh to be installed, so we test it on macOS only.
278+
#[cfg(target_os = "macos")]
279+
".zshenv",
280+
]
281+
.map(|rc| cx.config.homedir.join(rc));
282+
283+
for rc in &rcs {
284+
raw::write_file(rc, FAKE_RC).unwrap();
285+
}
286+
287+
let expected = FAKE_RC.to_owned() + &source(cx.config.cargodir.display(), POSIX_SH);
288+
289+
cx.config.expect(&INIT_NONE).await.is_ok();
290+
// sanity check
291+
for rc in &rcs {
292+
let new_rc = fs::read_to_string(rc).unwrap();
293+
assert_eq!(
294+
new_rc, expected,
295+
"Rc file {rc:?} does not contain a source after rustup-init",
296+
);
297+
}
298+
299+
cx.config
300+
.expect(&["rustup", "self", "uninstall", "-y", "--no-modify-path"])
301+
.await
302+
.is_ok();
303+
for rc in &rcs {
304+
let new_rc = fs::read_to_string(rc).unwrap();
305+
assert_eq!(
306+
new_rc, expected,
307+
"Rc file {rc:?} does not contain a source after uninstall",
308+
);
309+
}
310+
}
311+
269312
#[tokio::test]
270313
async fn install_adds_sources_while_removing_legacy_paths() {
271314
let cx = CliTestContext::new(Scenario::Empty).await;
@@ -422,6 +465,30 @@ mod windows {
422465
assert!(!get_path_().contains(&cfg_path));
423466
}
424467

468+
#[tokio::test]
469+
async fn uninstall_doesnt_affect_path_with_no_modify_path() {
470+
let cx = CliTestContext::new(Scenario::Empty).await;
471+
let _guard = RegistryGuard::new(&USER_PATH).unwrap();
472+
let cfg_path = cx.config.cargodir.join("bin").display().to_string();
473+
let get_path_ = || {
474+
HSTRING::try_from(get_path().unwrap().unwrap())
475+
.unwrap()
476+
.to_string()
477+
};
478+
479+
cx.config.expect(&INIT_NONE).await.is_ok();
480+
cx.config
481+
.expect(&["rustup", "self", "uninstall", "-y", "--no-modify-path"])
482+
.await
483+
.is_ok();
484+
assert!(
485+
get_path_().contains(cfg_path.trim_matches('"')),
486+
"`{}` not in `{}`",
487+
cfg_path,
488+
get_path_()
489+
);
490+
}
491+
425492
#[tokio::test]
426493
/// Smoke test for end-to-end code connectivity of the installer path mgmt on windows.
427494
async fn install_uninstall_affect_path_with_non_unicode() {

0 commit comments

Comments
 (0)