From 43402df89629a25ce0e63c73d756a3bf49acc589 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 26 Feb 2019 16:53:36 -0800 Subject: [PATCH] [Fix] `nvm_supports_source_options`: work around a bug in bash 3.2 See https://github.com/creationix/nvm/issues/1978#issuecomment-453480231 Fixes #1978. --- nvm.sh | 5 +++- .../Unit tests/nvm_supports_source_options | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100755 test/fast/Unit tests/nvm_supports_source_options diff --git a/nvm.sh b/nvm.sh index 3170252..01213a3 100644 --- a/nvm.sh +++ b/nvm.sh @@ -3559,7 +3559,10 @@ nvm_install_default_packages() { nvm_supports_source_options() { # shellcheck disable=SC1091,SC2240 - [ "_$(nvm_echo '[ $# -gt 0 ] && nvm_echo $1' | . /dev/stdin yes 2>/dev/null)" = "_yes" ] + [ "_$( . /dev/stdin yes 2> /dev/null <<'EOF' +[ $# -gt 0 ] && nvm_echo $1 +EOF + )" = "_yes" ] } nvm_supports_xz() { diff --git a/test/fast/Unit tests/nvm_supports_source_options b/test/fast/Unit tests/nvm_supports_source_options new file mode 100755 index 0000000..ceeff91 --- /dev/null +++ b/test/fast/Unit tests/nvm_supports_source_options @@ -0,0 +1,27 @@ +#!/bin/sh + +die () { echo "$@" ; exit 1; } + +\. ../../../nvm.sh + +x=0 +i=0 +runs=5 +calls=500 +first_result=false +if (nvm_supports_source_options && printf .); then + first_result=true +fi +while [ $x -le $runs ]; do + y=$x + x=$(( x + 1 )) + while [ $i -le $calls ]; do + this_result=false + if (nvm_supports_source_options && printf .); then + this_result=true + fi + [ $this_result = $first_result ] || die "call ${i}, run ${y} got ${this_result}; expected ${first_result}" + i=$(( i + 1 )) + done +done +echo "${runs} runs of ${calls} calls succeeded"