Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check to nvm profile for nvm path #2467

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions test/install_script/nvm_check_if_path_exists
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

setup () {
HOME="."
NVM_ENV=testing \. ../../install.sh
touch ".bashrc"
touch ".zshrc"
touch ".profile"
}

cleanup () {
unset HOME
unset NVM_ENV
unset NVM_DETECT_PROFILE
unset BASH_VERSION
unset ZSH_VERSION
unset -f setup cleanup die
rm -f ".bashrc" ".bash_profile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&1
}

die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }

setup

# check if nvm_path already exists in bashrc
NVM_DETECT_PROFILE="$(BASH_VERSION="1"; unset PROFILE; nvm_detect_profile)"
echo "export NVM_DIR="$HOME/.nvm"" > $HOME/.bashrc
OUTPUT = "$(nvm_do_install)"
EXPECTED_OUTPUT='nvm source string already in ${NVM_PROFILE}'
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
die "Path already exists in the profile, so should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
fi

# .zshrc should be detected for zsh
NVM_DETECT_PROFILE="$(ZSH_VERSION="1"; unset PROFILE; unset BASH_VERSION; nvm_detect_profile)"
echo "export NVM_DIR="$HOME/.nvm"" > $HOME/.zshrc
OUTPUT = "$(nvm_do_install)"
EXPECTED_OUTPUT='nvm source string already in ${NVM_PROFILE}'
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
die "Path already exists in the profile, so should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
sladyn98 marked this conversation as resolved.
Show resolved Hide resolved
fi