Skip to content
Myr

[Fix] `install.sh`: do not log when user has requested no profile modifications

Before adoption: this commit came in with the history the project adopted, so no landing records it.

[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

authored by Wes Todd · committed by Jordan Harband · parent 0509776 · Browse files · 2 files+66 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Wes Todd <wes@wesleytodd.com>
  • Co-authored-by: Jordan Harband <ljharb@gmail.com>

Diff stats

2 files+66 added−1 removed

  • tests:+62 added−0 removed
  • other:+4 added−1 removed

2 files+66 added−1 removed

added:test/install_script/nvm_install_profile_skip+62 added
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 setup cleanup die8 unset NVM_ENV METHOD PROFILE9}1011setup() {12 NVM_ENV=testing \. ../../install.sh1314 # Mock installation functions to do nothing15 install_nvm_from_git() { :; }16 install_nvm_as_script() { :; }1718 # Mock nvm_has to return true for git (to take the git path)19 nvm_has() {20 case "$1" in21 git) return 0 ;;22 xcode-select) return 1 ;;23 *) return 1 ;;24 esac25 }2627 # Mock nvm_detect_profile to return empty (no profile found)28 nvm_detect_profile() {29 echo ""30 }31}3233setup3435#36# Test: When PROFILE="/dev/null", no "Profile not found" warning should appear37#3839OUTPUT="$(PROFILE='/dev/null' METHOD='' NVM_DIR="$(mktemp -d)" nvm_do_install 2>&1)"40if echo "$OUTPUT" | grep -q "Profile not found"; then41 die "nvm_do_install should NOT show 'Profile not found' when PROFILE=/dev/null, got: $OUTPUT"42fi4344#45# Test: When PROFILE is empty/unset, the "Profile not found" warning SHOULD appear46#4748OUTPUT="$(PROFILE='' METHOD='' NVM_DIR="$(mktemp -d)" nvm_do_install 2>&1)"49if ! echo "$OUTPUT" | grep -q "Profile not found"; then50 die "nvm_do_install should show 'Profile not found' when PROFILE is empty, got: $OUTPUT"51fi5253#54# Test: When PROFILE points to a non-existent file, the "Profile not found" warning SHOULD appear55#5657OUTPUT="$(PROFILE='/nonexistent/profile' METHOD='' NVM_DIR="$(mktemp -d)" nvm_do_install 2>&1)"58if ! echo "$OUTPUT" | grep -q "Profile not found"; then59 die "nvm_do_install should show 'Profile not found' when PROFILE points to nonexistent file, got: $OUTPUT"60fi6162cleanup
modified:install.sh+4 added-1 removed
426 unmodified lines
427 # shellcheck disable=SC2016428 COMPLETION_STR='[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n'429 BASH_OR_ZSH=false430431 if [ "${PROFILE-}" = '/dev/null' ] ; then432 # the user has specifically requested NOT to have nvm touch their profile433 echo431 if [ -z "${NVM_PROFILE-}" ] ; then434 elif [ -z "${NVM_PROFILE-}" ] ; then435 local TRIED_PROFILE436 if [ -n "${PROFILE}" ]; then437 TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "438 fi
60 unmodified lines