From 7f88eabd0ba63a76a294c045f21a407dc9ec11a2 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 11 Dec 2014 18:47:09 +0100 Subject: [PATCH 1/2] Improve `pyenv version`, if there is one missing Display the other available ones still. Fixes https://github.com/yyuu/pyenv/issues/291 --- libexec/pyenv-version-name | 7 ++++++- test/version-name.bats | 20 ++++++++++++++++++++ test/version.bats | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/libexec/pyenv-version-name b/libexec/pyenv-version-name index c15178e2..7ed2a197 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}") @@ -31,7 +32,7 @@ OLDIFS="$IFS" versions=("${versions[@]}" "${version#python-}") else echo "pyenv: version \`$version' is not installed" >&2 - exit 1 + any_not_installed=1 fi done } @@ -42,3 +43,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 2d7ebe20..2556e005 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -52,6 +52,26 @@ 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 < ".python-version" <<<"python-2.7.6" diff --git a/test/version.bats b/test/version.bats index 296cfd59..8d933d28 100644 --- a/test/version.bats +++ b/test/version.bats @@ -36,3 +36,24 @@ 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_success + assert_output < Date: Thu, 11 Dec 2014 20:37:03 +0100 Subject: [PATCH 2/2] Use exitcode from pyenv-version-name in pyenv-version, do not halt --- libexec/pyenv-version | 5 ++++- test/version-name.bats | 13 +++++++++++++ test/version.bats | 17 +++++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) 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/test/version-name.bats b/test/version-name.bats index 2556e005..00e4771b 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -72,6 +72,19 @@ pyenv: version \`1.2' is not installed OUT } +pyenv-version-name-without-stderr() { + pyenv-version-name 2>/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 8d933d28..120ec51d 100644 --- a/test/version.bats +++ b/test/version.bats @@ -40,7 +40,7 @@ setup() { @test "set by PYENV_VERSION, one missing" { create_version "3.3.3" PYENV_VERSION=3.3.3:1.2 run pyenv-version - assert_success + 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 <