Check ZDOTDIR when adding path to .zprofile

Fixes #1036
This commit is contained in:
Wim Looman
2017-04-06 19:54:24 +02:00
parent 904ecf0a97
commit ae7173fb8d
3 changed files with 48 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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() {