nvm_do_install_tried_profile
This file
Path
test/install_script/nvm_do_install_tried_profile
68 lines · 2.0 KiB
Last changed by
[Fix] `install.sh`: fix POSIX compliance, printf format strings, and profile detectionJordan Harbandbefore adoption581317d
History of this fileTake it
1#!/bin/sh23die () { echo "$@" ; cleanup ; exit 1; }45cleanup() {6 unset -f install_nvm_from_git install_nvm_as_script nvm_detect_profile nvm_has7 unset -f nvm_check_global_modules nvm_install_node8 unset -f setup cleanup die9 unset NVM_ENV METHOD PROFILE10}1112setup() {13 NVM_ENV=testing \. ../../install.sh1415 # Mock installation functions to do nothing16 install_nvm_from_git() { :; }17 install_nvm_as_script() { :; }18 nvm_check_global_modules() { :; }19 nvm_install_node() { :; }2021 # Mock nvm_has to return true for git22 nvm_has() {23 case "$1" in24 git) return 0 ;;25 xcode-select) return 1 ;;26 *) return 1 ;;27 esac28 }2930 # Mock nvm_detect_profile to return empty (profile not found)31 nvm_detect_profile() {32 echo ""33 }34}3536setup3738#39# Test: When PROFILE is set to a non-/dev/null value but nvm_detect_profile40# returns empty, the "Profile not found" message should include the PROFILE41# value in the TRIED_PROFILE string.42#43# Before the fix, TRIED_PROFILE was set to "${NVM_PROFILE} (as defined in $PROFILE)"44# but NVM_PROFILE is known to be empty at that point, so the message would say45# " (as defined in $PROFILE)" instead of "/some/path (as defined in $PROFILE)".46#4748OUTPUT="$(PROFILE='/my/custom/profile' METHOD='' NVM_DIR="$(mktemp -d)" nvm_do_install 2>&1)"4950# The output should mention /my/custom/profile in the "Tried" line51if ! echo "${OUTPUT}" | grep -q '/my/custom/profile (as defined in \$PROFILE)'; then52 # Check without the escaped dollar sign too53 if ! echo "${OUTPUT}" | grep -q '/my/custom/profile'; then54 die "Expected TRIED_PROFILE to contain '/my/custom/profile', got: ${OUTPUT}"55 fi56fi5758# Verify the "Profile not found" message appears59if ! echo "${OUTPUT}" | grep -q 'Profile not found'; then60 die "Expected 'Profile not found' message, got: ${OUTPUT}"61fi6263# The message should NOT start with " (as defined" (which would indicate empty TRIED_PROFILE prefix)64if echo "${OUTPUT}" | grep -q 'Tried (as defined'; then65 die "TRIED_PROFILE appears to have an empty prefix (NVM_PROFILE instead of PROFILE), got: ${OUTPUT}"66fi6768cleanup