Skip to content

Commit

Permalink
Don't check SHELL for bash before writing .bash_profile. Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Jun 24, 2017
1 parent a947d66 commit 579399f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,15 +1041,13 @@ fn get_add_path_methods() -> Vec<PathUpdateMethod> {
let zprofile = zdotdir.map(|p| p.join(".zprofile"));
profiles.push(zprofile);
}
}

if shell.contains("bash") {
if let Some(bash_profile) = utils::home_dir().map(|p| p.join(".bash_profile")) {
// Only update .bash_profile if it exists because creating .bash_profile
// will cause .profile to not be read
if bash_profile.exists() {
profiles.push(Some(bash_profile));
}
}
if let Some(bash_profile) = utils::home_dir().map(|p| p.join(".bash_profile")) {
// Only update .bash_profile if it exists because creating .bash_profile
// will cause .profile to not be read
if bash_profile.exists() {
profiles.push(Some(bash_profile));
}
}

Expand Down
25 changes: 24 additions & 1 deletion tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,23 @@ fn install_adds_path_to_profile() {
install_adds_path_to_rc(".profile");
}

#[test]
#[cfg(unix)]
fn install_adds_path_to_bash_profile() {
install_adds_path_to_rc(".bash_profile");
}

#[test]
#[cfg(unix)]
fn install_does_not_add_path_to_bash_profile_that_doesnt_exist() {
setup(&|config| {
let ref rc = config.homedir.join(".bash_profile");
expect_ok(config, &["rustup-init", "-y"]);

assert!(!rc.exists());
});
}

#[test]
#[cfg(unix)]
fn install_with_zsh_adds_path_to_zprofile() {
Expand Down Expand Up @@ -399,10 +416,16 @@ fn uninstall_removes_path_from_rc(rcfile: &str) {

#[test]
#[cfg(unix)]
fn uninstall_removes_path_from_bashrc() {
fn uninstall_removes_path_from_profile() {
uninstall_removes_path_from_rc(".profile");
}

#[test]
#[cfg(unix)]
fn uninstall_removes_path_from_bash_profile() {
uninstall_removes_path_from_rc(".bash_profile");
}

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

0 comments on commit 579399f

Please sign in to comment.