Skip to content

Commit 96a53c2

Browse files
authored
Merge pull request #1038 from Nemo157/zdotdir
Check ZDOTDIR when adding path to .zprofile
2 parents 904ecf0 + ae7173f commit 96a53c2

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/rustup-cli/self_update.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,11 @@ fn get_add_path_methods() -> Vec<PathUpdateMethod> {
981981

982982
if let Ok(shell) = env::var("SHELL") {
983983
if shell.contains("zsh") {
984-
let zprofile = utils::home_dir().map(|p| p.join(".zprofile"));
984+
let zdotdir = env::var("ZDOTDIR")
985+
.ok()
986+
.map(PathBuf::from)
987+
.or_else(utils::home_dir);
988+
let zprofile = zdotdir.map(|p| p.join(".zprofile"));
985989
profiles.push(zprofile);
986990
}
987991
}

src/rustup-mock/src/clitools.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub fn setup(s: Scenario, f: &Fn(&Config)) {
6363
// Unset env variables that will break our testing
6464
env::remove_var("RUSTUP_TOOLCHAIN");
6565
env::remove_var("SHELL");
66+
env::remove_var("ZDOTDIR");
6667

6768
let exedir = TempDir::new("rustup-exe").unwrap();
6869
let distdir = TempDir::new("rustup-dist").unwrap();

tests/cli-self-upd.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,48 @@ fn install_adds_path_to_profile() {
323323
install_adds_path_to_rc(".profile");
324324
}
325325

326+
#[test]
327+
#[cfg(unix)]
328+
fn install_with_zsh_adds_path_to_zprofile() {
329+
setup(&|config| {
330+
let my_rc = "foo\nbar\nbaz";
331+
let ref rc = config.homedir.join(".zprofile");
332+
raw::write_file(rc, my_rc).unwrap();
333+
334+
let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]);
335+
cmd.env("SHELL", "zsh");
336+
assert!(cmd.output().unwrap().status.success());
337+
338+
let new_rc = raw::read_file(rc).unwrap();
339+
let addition = format!(r#"export PATH="{}/bin:$PATH""#,
340+
config.cargodir.display());
341+
let expected = format!("{}\n{}\n", my_rc, addition);
342+
assert_eq!(new_rc, expected);
343+
});
344+
}
345+
346+
#[test]
347+
#[cfg(unix)]
348+
fn install_with_zsh_adds_path_to_zdotdir_zprofile() {
349+
setup(&|config| {
350+
let zdotdir = TempDir::new("zdotdir").unwrap();
351+
let my_rc = "foo\nbar\nbaz";
352+
let ref rc = zdotdir.path().join(".zprofile");
353+
raw::write_file(rc, my_rc).unwrap();
354+
355+
let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]);
356+
cmd.env("SHELL", "zsh");
357+
cmd.env("ZDOTDIR", zdotdir.path());
358+
assert!(cmd.output().unwrap().status.success());
359+
360+
let new_rc = raw::read_file(rc).unwrap();
361+
let addition = format!(r#"export PATH="{}/bin:$PATH""#,
362+
config.cargodir.display());
363+
let expected = format!("{}\n{}\n", my_rc, addition);
364+
assert_eq!(new_rc, expected);
365+
});
366+
}
367+
326368
#[test]
327369
#[cfg(unix)]
328370
fn install_adds_path_to_rcfile_just_once() {

0 commit comments

Comments
 (0)