Files
nvm/test/install_script/nvm_install_profile_skip
Wes Todd ec8906b284 [Fix] install.sh: do not log when user has requested no profile modifications
[Tests] `install.sh`: add tests for PROFILE=/dev/null profile skip

Verify that when PROFILE="/dev/null" is set:
- The "Profile not found" warning is suppressed
- Profile modification is skipped as expected

Co-authored-by: Wes Todd <wes@wesleytodd.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2019-12-05 19:30:26 -08:00

63 lines
1.6 KiB
Bash
Executable File

#!/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