Skip to content

Commit

Permalink
zsh install support
Browse files Browse the repository at this point in the history
  • Loading branch information
polonez committed Mar 27, 2017
1 parent 2ae338d commit aa3c0b0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
9 changes: 8 additions & 1 deletion src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,14 @@ fn get_add_path_methods() -> Vec<PathUpdateMethod> {
return vec![PathUpdateMethod::Windows];
}

let profile = utils::home_dir().map(|p| p.join(".profile"));
let mut profile_name = ".profile";
if let Ok(shell) = env::var("SHELL") {
if shell.contains("zsh") {
profile_name = ".zprofile";
}
}

let profile = utils::home_dir().map(|p| p.join(profile_name));
let rcfiles = vec![profile].into_iter().filter_map(|f|f);

rcfiles.map(PathUpdateMethod::RcFile).collect()
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 @@ -62,6 +62,7 @@ pub static MULTI_ARCH1: &'static str = "i686-unknown-linux-gnu";
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");

let exedir = TempDir::new("rustup-exe").unwrap();
let distdir = TempDir::new("rustup-dist").unwrap();
Expand Down
35 changes: 22 additions & 13 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,25 +302,34 @@ fn uninstall_stress_test() {
}

#[cfg(unix)]
fn install_adds_path_to_rc(rcfile: &str) {
setup(&|config| {
let my_rc = "foo\nbar\nbaz";
let ref rc = config.homedir.join(rcfile);
raw::write_file(rc, my_rc).unwrap();
expect_ok(config, &["rustup-init", "-y"]);
fn install_adds_path_to_rc(config: &Config, rcfile: &str) {
let my_rc = "foo\nbar\nbaz";
let ref rc = config.homedir.join(rcfile);
raw::write_file(rc, my_rc).unwrap();
expect_ok(config, &["rustup-init", "-y"]);

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);
});
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_profile() {
install_adds_path_to_rc(".profile");
setup(&|config| {
install_adds_path_to_rc(config, ".profile");
});
}

#[test]
#[cfg(unix)]
fn install_adds_path_to_zprofile() {
setup(&|config| {
env::set_var("SHELL", "/bin/zsh");
install_adds_path_to_rc(config, ".zprofile");
});
}

#[test]
Expand Down

0 comments on commit aa3c0b0

Please sign in to comment.