Use exitcode from pyenv-version-name in pyenv-version, do not halt

This commit is contained in:
Daniel Hahler 2014-12-11 20:37:03 +01:00
parent 7f88eabd0b
commit e8433cfeb3
3 changed files with 32 additions and 3 deletions

View file

@ -8,10 +8,13 @@
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
exitcode=0
OLDIFS="$IFS" OLDIFS="$IFS"
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) || exitcode=$?
IFS="$OLDIFS" IFS="$OLDIFS"
for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do
echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))" echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))"
done done
exit $exitcode

View file

@ -72,6 +72,19 @@ pyenv: version \`1.2' is not installed
OUT 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 <<OUT
3.4.2
OUT
}
@test "version with prefix in name" { @test "version with prefix in name" {
create_version "2.7.6" create_version "2.7.6"
cat > ".python-version" <<<"python-2.7.6" cat > ".python-version" <<<"python-2.7.6"

View file

@ -40,7 +40,7 @@ setup() {
@test "set by PYENV_VERSION, one missing" { @test "set by PYENV_VERSION, one missing" {
create_version "3.3.3" create_version "3.3.3"
PYENV_VERSION=3.3.3:1.2 run pyenv-version PYENV_VERSION=3.3.3:1.2 run pyenv-version
assert_success assert_failure
assert_output <<OUT assert_output <<OUT
pyenv: version \`1.2' is not installed pyenv: version \`1.2' is not installed
3.3.3 (set by PYENV_VERSION environment variable) 3.3.3 (set by PYENV_VERSION environment variable)
@ -50,10 +50,23 @@ OUT
@test "set by PYENV_VERSION, two missing" { @test "set by PYENV_VERSION, two missing" {
create_version "3.3.3" create_version "3.3.3"
PYENV_VERSION=3.4.2:3.3.3:1.2 run pyenv-version PYENV_VERSION=3.4.2:3.3.3:1.2 run pyenv-version
assert_success assert_failure
assert_output <<OUT assert_output <<OUT
pyenv: version \`3.4.2' is not installed pyenv: version \`3.4.2' is not installed
pyenv: version \`1.2' is not installed pyenv: version \`1.2' is not installed
3.3.3 (set by PYENV_VERSION environment variable) 3.3.3 (set by PYENV_VERSION environment variable)
OUT OUT
} }
pyenv-version-without-stderr() {
pyenv-version 2>/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 <<OUT
3.3.3 (set by PYENV_VERSION environment variable)
OUT
}