Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ nvm_do_install() {
COMPLETION_STR='[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n'
BASH_OR_ZSH=false

if [ -z "${NVM_PROFILE-}" ] ; then
if [ "${PROFILE-}" = '/dev/null' ] ; then
# the user has specifically requested NOT to have nvm touch their profile
echo
elif [ -z "${NVM_PROFILE-}" ] ; then
local TRIED_PROFILE
if [ -n "${PROFILE}" ]; then
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
Expand Down
62 changes: 62 additions & 0 deletions test/install_script/nvm_install_profile_skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh

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

cleanup() {
unset -f install_nvm_from_git install_nvm_as_script nvm_detect_profile nvm_has
unset -f setup cleanup die
unset NVM_ENV METHOD PROFILE
}

setup() {
NVM_ENV=testing \. ../../install.sh

# Mock installation functions to do nothing
install_nvm_from_git() { :; }
install_nvm_as_script() { :; }

# Mock nvm_has to return true for git (to take the git path)
nvm_has() {
case "$1" in
git) return 0 ;;
xcode-select) return 1 ;;
*) return 1 ;;
esac
}

# Mock nvm_detect_profile to return empty (no profile found)
nvm_detect_profile() {
echo ""
}
}

setup

#
# Test: When PROFILE="/dev/null", no "Profile not found" warning should appear
#

OUTPUT="$(PROFILE='/dev/null' METHOD='' NVM_DIR="$(mktemp -d)" nvm_do_install 2>&1)"
if echo "$OUTPUT" | grep -q "Profile not found"; then
die "nvm_do_install should NOT show 'Profile not found' when PROFILE=/dev/null, got: $OUTPUT"
fi

#
# Test: When PROFILE is empty/unset, the "Profile not found" warning SHOULD appear
#

OUTPUT="$(PROFILE='' METHOD='' NVM_DIR="$(mktemp -d)" nvm_do_install 2>&1)"
if ! echo "$OUTPUT" | grep -q "Profile not found"; then
die "nvm_do_install should show 'Profile not found' when PROFILE is empty, got: $OUTPUT"
fi

#
# Test: When PROFILE points to a non-existent file, the "Profile not found" warning SHOULD appear
#

OUTPUT="$(PROFILE='/nonexistent/profile' METHOD='' NVM_DIR="$(mktemp -d)" nvm_do_install 2>&1)"
if ! echo "$OUTPUT" | grep -q "Profile not found"; then
die "nvm_do_install should show 'Profile not found' when PROFILE points to nonexistent file, got: $OUTPUT"
fi

cleanup
Loading