Skip to content

Commit

Permalink
Check ZDOTDIR when adding path to .zprofile
Browse files Browse the repository at this point in the history
Fixes #1036
  • Loading branch information
Nemo157 committed Apr 6, 2017
1 parent 904ecf0 commit ae7173f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,11 @@ fn get_add_path_methods() -> Vec<PathUpdateMethod> {

if let Ok(shell) = env::var("SHELL") {
if shell.contains("zsh") {
let zprofile = utils::home_dir().map(|p| p.join(".zprofile"));
let zdotdir = env::var("ZDOTDIR")
.ok()
.map(PathBuf::from)
.or_else(utils::home_dir);
let zprofile = zdotdir.map(|p| p.join(".zprofile"));
profiles.push(zprofile);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rustup-mock/src/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub fn setup(s: Scenario, f: &Fn(&Config)) {
// Unset env variables that will break our testing
env::remove_var("RUSTUP_TOOLCHAIN");
env::remove_var("SHELL");
env::remove_var("ZDOTDIR");

let exedir = TempDir::new("rustup-exe").unwrap();
let distdir = TempDir::new("rustup-dist").unwrap();
Expand Down
42 changes: 42 additions & 0 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,48 @@ fn install_adds_path_to_profile() {
install_adds_path_to_rc(".profile");
}

#[test]
#[cfg(unix)]
fn install_with_zsh_adds_path_to_zprofile() {
setup(&|config| {
let my_rc = "foo\nbar\nbaz";
let ref rc = config.homedir.join(".zprofile");
raw::write_file(rc, my_rc).unwrap();

let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]);
cmd.env("SHELL", "zsh");
assert!(cmd.output().unwrap().status.success());

let new_rc = raw::read_file(rc).unwrap();
let addition = format!(r#"export PATH="{}/bin:$PATH""#,
config.cargodir.display());
let expected = format!("{}\n{}\n", my_rc, addition);
assert_eq!(new_rc, expected);
});
}

#[test]
#[cfg(unix)]
fn install_with_zsh_adds_path_to_zdotdir_zprofile() {
setup(&|config| {
let zdotdir = TempDir::new("zdotdir").unwrap();
let my_rc = "foo\nbar\nbaz";
let ref rc = zdotdir.path().join(".zprofile");
raw::write_file(rc, my_rc).unwrap();

let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]);
cmd.env("SHELL", "zsh");
cmd.env("ZDOTDIR", zdotdir.path());
assert!(cmd.output().unwrap().status.success());

let new_rc = raw::read_file(rc).unwrap();
let addition = format!(r#"export PATH="{}/bin:$PATH""#,
config.cargodir.display());
let expected = format!("{}\n{}\n", my_rc, addition);
assert_eq!(new_rc, expected);
});
}

#[test]
#[cfg(unix)]
fn install_adds_path_to_rcfile_just_once() {
Expand Down

0 comments on commit ae7173f

Please sign in to comment.