diff --git a/libexec/pyenv-version b/libexec/pyenv-version index cec2c945..dd5fa29a 100755 --- a/libexec/pyenv-version +++ b/libexec/pyenv-version @@ -8,10 +8,13 @@ set -e [ -n "$PYENV_DEBUG" ] && set -x +exitcode=0 OLDIFS="$IFS" -IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) +IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) || exitcode=$? IFS="$OLDIFS" for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))" done + +exit $exitcode diff --git a/libexec/pyenv-version-name b/libexec/pyenv-version-name index 42c04c62..02820012 100755 --- a/libexec/pyenv-version-name +++ b/libexec/pyenv-version-name @@ -21,6 +21,7 @@ version_exists() { versions=() OLDIFS="$IFS" { IFS=: + any_not_installed=0 for version in ${PYENV_VERSION}; do if version_exists "$version" || [ "$version" = "system" ]; then versions=("${versions[@]}" "${version}") @@ -28,7 +29,7 @@ OLDIFS="$IFS" versions=("${versions[@]}" "${version#python-}") else echo "pyenv: version \`$version' is not installed" >&2 - exit 1 + any_not_installed=1 fi done } @@ -39,3 +40,7 @@ OLDIFS="$IFS" echo "${versions[*]}" } IFS="$OLDIFS" + +if [ "$any_not_installed" = 1 ]; then + exit 1 +fi diff --git a/test/version-name.bats b/test/version-name.bats index 951d3e72..6d386076 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -52,6 +52,39 @@ setup() { assert_failure "pyenv: version \`1.2' is not installed" } +@test "one missing version (second missing)" { + create_version "3.4.2" + PYENV_VERSION="3.4.2:1.2" run pyenv-version-name + assert_failure + assert_output </dev/null +} + +@test "one missing version (without stderr)" { + create_version "3.4.2" + PYENV_VERSION="1.2:3.4.2" run pyenv-version-name-without-stderr + assert_failure + assert_output < ".python-version" <<<"python-2.7.6" diff --git a/test/version.bats b/test/version.bats index 296cfd59..120ec51d 100644 --- a/test/version.bats +++ b/test/version.bats @@ -36,3 +36,37 @@ setup() { run pyenv-version assert_success "3.3.3 (set by ${PYENV_ROOT}/version)" } + +@test "set by PYENV_VERSION, one missing" { + create_version "3.3.3" + PYENV_VERSION=3.3.3:1.2 run pyenv-version + assert_failure + assert_output </dev/null +} + +@test "set by PYENV_VERSION, one missing (stderr filtered)" { + create_version "3.3.3" + PYENV_VERSION=3.4.2:3.3.3 run pyenv-version-without-stderr + assert_failure + assert_output <