Fix broken tests

This commit is contained in:
Yamashita Yuu 2014-01-03 02:05:40 +09:00
parent 88922e2bc0
commit 3dd9332eee
9 changed files with 62 additions and 47 deletions

View file

@ -38,13 +38,14 @@ versions=($@)
if [ "$versions" = "--unset" ]; then if [ "$versions" = "--unset" ]; then
rm -f .python-version .pyenv-version rm -f .python-version .pyenv-version
elif [ -n "$versions" ]; then elif [ -n "$versions" ]; then
if [ "$(PYENV_VERSION= pyenv-version-origin)" -ef .pyenv-version ]; then previous_file="$(PYENV_VERSION= pyenv-version-origin || true)"
pyenv-version-file-write .python-version "${versions[@]}"
if [ "$previous_file" -ef .pyenv-version ]; then
rm -f .pyenv-version rm -f .pyenv-version
{ echo "pyenv: removed existing \`.pyenv-version' file and migrated" { echo "pyenv: removed existing \`.pyenv-version' file and migrated"
echo " local version specification to \`.python-version' file" echo " local version specification to \`.python-version' file"
} >&2 } >&2
fi fi
pyenv-version-file-write .python-version "${versions[@]}"
else else
OLDIFS="$IFS" OLDIFS="$IFS"
IFS=: versions=($( IFS=: versions=($(

View file

@ -16,32 +16,38 @@ if [ "$1" = "--complete" ]; then
fi fi
if [ -n "$1" ]; then if [ -n "$1" ]; then
versions=($@)
OLDIFS="$IFS" OLDIFS="$IFS"
IFS=: PYENV_VERSION="${versions[*]}" { IFS=:
IFS="$OLDIFS" export PYENV_VERSION="$*"
export PYENV_VERSION }
else
OLDIFS="$IFS"
IFS=: versions=($(pyenv-version-name))
IFS="$OLDIFS" IFS="$OLDIFS"
elif [ -z "$PYENV_VERSION" ]; then
PYENV_VERSION="$(pyenv-version-name)"
fi fi
PYENV_PREFIX_PATHS=() PYENV_PREFIX_PATHS=()
for version in "${versions[@]}"; do OLDIFS="$IFS"
if [ "$version" = "system" ]; then { IFS=:
PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python || true)" for version in ${PYENV_VERSION}; do
PYENV_PREFIX_PATH="${PYTHON_PATH%/bin/*}" if [ "$version" = "system" ]; then
else if PYTHON_PATH="$(pyenv-which python 2>/dev/null)"; then
PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}" PYENV_PREFIX_PATH="${PYTHON_PATH%/bin/*}"
fi else
if [ -d "$PYENV_PREFIX_PATH" ]; then echo "pyenv: system version not found in PATH" >&2
PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH") exit 1
else fi
echo "pyenv: version \`${version}' not installed" >&2 else
exit 1 PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}"
fi fi
done if [ -d "$PYENV_PREFIX_PATH" ]; then
PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH")
else
echo "pyenv: version \`${version}' not installed" >&2
exit 1
fi
done
}
IFS="$OLDIFS"
OLDIFS="$IFS" OLDIFS="$IFS"
{ IFS=: { IFS=:

View file

@ -5,7 +5,7 @@ set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
PYENV_VERSION_FILE="$1" PYENV_VERSION_FILE="$1"
shift shift || true
versions=("$@") versions=("$@")
if [ -z "$versions" ] || [ -z "$PYENV_VERSION_FILE" ]; then if [ -z "$versions" ] || [ -z "$PYENV_VERSION_FILE" ]; then

View file

@ -5,18 +5,10 @@ set -e
if [ -z "$PYENV_VERSION" ]; then if [ -z "$PYENV_VERSION" ]; then
PYENV_VERSION_FILE="$(pyenv-version-file)" PYENV_VERSION_FILE="$(pyenv-version-file)"
OLDIFS="$IFS" PYENV_VERSION="$(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)"
IFS=: versions=($(pyenv-version-file-read "$PYENV_VERSION_FILE" || true))
IFS=: PYENV_VERSION="${versions[*]}"
IFS="$OLDIFS"
export PYENV_VERSION
else
OLDIFS="$IFS"
IFS=: versions=($(echo "${PYENV_VERSION}"))
IFS="$OLDIFS"
fi fi
if [ -z "$versions" ] || [ "$versions" = "system" ]; then if [ -z "$PYENV_VERSION" ] || [ "$PYENV_VERSION" = "system" ]; then
echo "system" echo "system"
exit exit
fi fi
@ -26,11 +18,27 @@ version_exists() {
[ -d "${PYENV_ROOT}/versions/${version}" ] [ -d "${PYENV_ROOT}/versions/${version}" ]
} }
for version in "${versions[@]}"; do versions=()
if [ "$version" != "system" ] && ! version_exists "$version"; then OLDIFS="$IFS"
echo "pyenv: version \`$version' is not installed" >&2 { IFS=:
exit 1 for version in ${PYENV_VERSION}; do
fi if version_exists "$version" || [ "$version" = "system" ]; then
done versions=("${versions[@]}" "${version}")
elif version_exists "${version#python-}"; then
{ echo "warning: ignoring extraneous \`python-' prefix in version \`${version}'"
echo " (set by $(pyenv-version-origin))"
} >&2
versions=("${versions[@]}" "${version#python-}")
else
echo "pyenv: version \`$version' is not installed" >&2
exit 1
fi
done
}
IFS="$OLDIFS"
echo "${PYENV_VERSION}" OLDIFS="$IFS"
{ IFS=:
echo "${versions[*]}"
}
IFS="$OLDIFS"

View file

@ -29,8 +29,8 @@ create_executable() {
run pyenv-completions exec run pyenv-completions exec
assert_success assert_success
assert_output <<OUT assert_output <<OUT
rake
python python
rake
OUT OUT
} }

View file

@ -5,7 +5,7 @@ load test_helper
@test "blank invocation" { @test "blank invocation" {
run pyenv run pyenv
assert_success assert_success
assert [ "${lines[0]}" = "pyenv 0.4.0" ] assert [ "${lines[0]}" == "pyenv 0.4.0-20131217" ]
} }
@test "invalid command" { @test "invalid command" {

View file

@ -47,9 +47,9 @@ create_executable() {
run ls "${PYENV_ROOT}/shims" run ls "${PYENV_ROOT}/shims"
assert_success assert_success
assert_output <<OUT assert_output <<OUT
python
rake rake
rspec rspec
python
OUT OUT
} }
@ -80,8 +80,8 @@ OUT
run ls "${PYENV_ROOT}/shims" run ls "${PYENV_ROOT}/shims"
assert_success assert_success
assert_output <<OUT assert_output <<OUT
rspec
python python
rspec
OUT OUT
} }

View file

@ -38,7 +38,7 @@ setup() {
@test "reads only the first word from file" { @test "reads only the first word from file" {
cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi" cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi"
run pyenv-version-file-read my-version run pyenv-version-file-read my-version
assert_success "1.9.3-p194@tag" assert_success "1.9.3-p194@tag:1.8.7:hi"
} }
@test "loads only the first line in file" { @test "loads only the first line in file" {
@ -47,7 +47,7 @@ setup() {
1.9.3 two 1.9.3 two
IN IN
run pyenv-version-file-read my-version run pyenv-version-file-read my-version
assert_success "1.8.7" assert_success "1.8.7:one:1.9.3:two"
} }
@test "ignores leading blank lines" { @test "ignores leading blank lines" {