1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-16 07:13:53 -05:00

Merge remote-tracking branch 'rbenv/master' into rbenv-20151121

This commit is contained in:
Yamashita, Yuu
2015-11-21 04:13:52 +00:00
24 changed files with 309 additions and 111 deletions

View File

@@ -6,6 +6,18 @@ setup() {
mkdir -p "$HOME"
git config --global user.name "Tester"
git config --global user.email "tester@test.local"
mkdir -p "${PYENV_TEST_DIR}/bin"
cat > "${PYENV_TEST_DIR}/bin/git" <<CMD
#!$BASH
if [[ \$1 == remote && \$PWD != "\$PYENV_TEST_DIR"/* ]]; then
echo "not allowed" >&2
exit 1
else
exec $(which git) "\$@"
fi
CMD
chmod +x "${PYENV_TEST_DIR}/bin/git"
}
git_commit() {
@@ -19,10 +31,25 @@ git_commit() {
[[ $output == "pyenv 20"* ]]
}
@test "doesn't read version from non-pyenv repo" {
mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT"
git init
git remote add origin https://github.com/homebrew/homebrew.git
git_commit
git tag v1.0
cd "$PYENV_TEST_DIR"
run pyenv---version
assert_success
[[ $output == "pyenv 20"* ]]
}
@test "reads version from git repo" {
mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT"
git init
git remote add origin https://github.com/yyuu/pyenv.git
git_commit
git tag v20380119
git_commit
@@ -38,6 +65,7 @@ git_commit() {
mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT"
git init
git remote add origin https://github.com/yyuu/pyenv.git
git_commit
cd "$PYENV_TEST_DIR"

View File

@@ -13,7 +13,7 @@ create_command() {
create_command "pyenv-hello" "#!$BASH
echo hello"
run pyenv-completions hello
assert_success ""
assert_success "--help"
}
@test "command with completion support" {
@@ -25,7 +25,11 @@ else
exit 1
fi"
run pyenv-completions hello
assert_success "hello"
assert_success
assert_output <<OUT
--help
hello
OUT
}
@test "forwards extra arguments" {
@@ -40,6 +44,7 @@ fi"
run pyenv-completions hello happy world
assert_success
assert_output <<OUT
--help
happy
world
OUT

View File

@@ -16,8 +16,16 @@ create_executable() {
@test "fails with invalid version" {
export PYENV_VERSION="3.4"
run pyenv-exec python -v
assert_failure "pyenv: version \`3.4' is not installed"
run pyenv-exec python -V
assert_failure "pyenv: version \`3.4' is not installed (set by PYENV_VERSION environment variable)"
}
@test "fails with invalid version set from file" {
mkdir -p "$PYENV_TEST_DIR"
cd "$PYENV_TEST_DIR"
echo 2.7 > .python-version
run pyenv-exec rspec
assert_failure "pyenv: version \`2.7' is not installed (set by $PWD/.python-version)"
}
@test "completes with names of executables" {
@@ -29,6 +37,7 @@ create_executable() {
run pyenv-completions exec
assert_success
assert_output <<OUT
--help
fab
python
OUT

View File

@@ -59,7 +59,13 @@ OUT
mkdir -p "$HOME"
touch "${HOME}/hola.bash"
ln -s "../../home/hola.bash" "${path}/exec/hello.bash"
touch "${path}/exec/bright.sh"
ln -s "bright.sh" "${path}/exec/world.bash"
PYENV_HOOK_PATH="$path" run pyenv-hooks exec
assert_success "${HOME}/hola.bash"
assert_success
assert_output <<OUT
${HOME}/hola.bash
${PYENV_TEST_DIR}/pyenv.d/exec/bright.sh
OUT
}

View File

@@ -14,7 +14,7 @@ load test_helper
@test "auto rehash" {
run pyenv-init -
assert_success
assert_line "pyenv rehash 2>/dev/null"
assert_line "command pyenv rehash 2>/dev/null"
}
@test "setup shell completions" {

View File

@@ -4,8 +4,8 @@ load test_helper
@test "blank invocation" {
run pyenv
assert_success
assert [ "${lines[0]}" == "pyenv 20151105" ]
assert_failure
assert_line 0 "$(pyenv---version)"
}
@test "invalid command" {

View File

@@ -1,18 +1,20 @@
unset PYENV_VERSION
unset PYENV_DIR
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
PYENV_TEST_DIR="$(realpath "$BATS_TMPDIR")/pyenv"
else
if [ -n "$PYENV_NATIVE_EXT" ]; then
echo "pyenv: failed to load \`realpath' builtin" >&2
exit 1
fi
PYENV_TEST_DIR="${BATS_TMPDIR}/pyenv"
fi
# guard against executing this block twice due to bats internals
if [ "$PYENV_ROOT" != "${PYENV_TEST_DIR}/root" ]; then
if [ -z "$PYENV_TEST_DIR" ]; then
PYENV_TEST_DIR="${BATS_TMPDIR}/pyenv"
export PYENV_TEST_DIR="$(mktemp -d "${PYENV_TEST_DIR}.XXX" 2>/dev/null || echo "$PYENV_TEST_DIR")"
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
export PYENV_TEST_DIR="$(realpath "$PYENV_TEST_DIR")"
else
if [ -n "$PYENV_NATIVE_EXT" ]; then
echo "pyenv: failed to load \`realpath' builtin" >&2
exit 1
fi
fi
export PYENV_ROOT="${PYENV_TEST_DIR}/root"
export HOME="${PYENV_TEST_DIR}/home"
@@ -22,6 +24,9 @@ if [ "$PYENV_ROOT" != "${PYENV_TEST_DIR}/root" ]; then
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
PATH="${PYENV_ROOT}/shims:$PATH"
export PATH
for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done
unset xdg_var
fi
teardown() {
@@ -106,7 +111,7 @@ assert() {
# but in which system utils necessary for pyenv operation are still available.
path_without() {
local exe="$1"
local path="${PATH}:"
local path=":${PATH}:"
local found alt util
for found in $(which -a "$exe"); do
found="${found%/*}"
@@ -118,8 +123,9 @@ path_without() {
ln -s "${found}/$util" "${alt}/$util"
fi
done
path="${path/${found}:/${alt}:}"
path="${path/:${found}:/:${alt}:}"
fi
done
path="${path#:}"
echo "${path%:}"
}

View File

@@ -49,7 +49,7 @@ setup() {
@test "missing version" {
PYENV_VERSION=1.2 run pyenv-version-name
assert_failure "pyenv: version \`1.2' is not installed"
assert_failure "pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)"
}
@test "one missing version (second missing)" {
@@ -57,7 +57,7 @@ setup() {
PYENV_VERSION="3.4.2:1.2" run pyenv-version-name
assert_failure
assert_output <<OUT
pyenv: version \`1.2' is not installed
pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.4.2
OUT
}
@@ -67,7 +67,7 @@ OUT
PYENV_VERSION="1.2:3.4.2" run pyenv-version-name
assert_failure
assert_output <<OUT
pyenv: version \`1.2' is not installed
pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.4.2
OUT
}

View File

@@ -42,7 +42,7 @@ setup() {
PYENV_VERSION=3.3.3:1.2 run pyenv-version
assert_failure
assert_output <<OUT
pyenv: version \`1.2' is not installed
pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.3.3 (set by PYENV_VERSION environment variable)
OUT
}
@@ -52,8 +52,8 @@ OUT
PYENV_VERSION=3.4.2:3.3.3:1.2 run pyenv-version
assert_failure
assert_output <<OUT
pyenv: version \`3.4.2' is not installed
pyenv: version \`1.2' is not installed
pyenv: version \`3.4.2' is not installed (set by PYENV_VERSION environment variable)
pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.3.3 (set by PYENV_VERSION environment variable)
OUT
}

View File

@@ -139,3 +139,18 @@ OUT
2.7.8
OUT
}
@test "doesn't list symlink aliases when --skip-aliases" {
create_version "1.8.7"
ln -s "1.8.7" "${PYENV_ROOT}/versions/1.8"
mkdir moo
ln -s "${PWD}/moo" "${PYENV_ROOT}/versions/1.9"
run pyenv-versions --bare --skip-aliases
assert_success
assert_output <<OUT
1.8.7
1.9
OUT
}

View File

@@ -62,15 +62,15 @@ create_executable() {
@test "version not installed" {
create_executable "3.4" "py.test"
PYENV_VERSION=3.3 run pyenv-which py.test
assert_failure "pyenv: version \`3.3' is not installed"
assert_failure "pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)"
}
@test "versions not installed" {
create_executable "3.4" "py.test"
PYENV_VERSION=2.7:3.3 run pyenv-which py.test
assert_failure <<OUT
pyenv: version \`2.7' is not installed
pyenv: version \`3.3' is not installed
pyenv: version \`2.7' is not installed (set by PYENV_VERSION environment variable)
pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)
OUT
}
@@ -80,6 +80,12 @@ OUT
assert_failure "pyenv: fab: command not found"
}
@test "no executable found for system version" {
export PATH="$(path_without "rake")"
PYENV_VERSION=system run pyenv-which rake
assert_failure "pyenv: rake: command not found"
}
@test "executable found in other versions" {
create_executable "2.7" "python"
create_executable "3.3" "py.test"