2014-01-02 16:48:22 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
2017-12-07 01:29:48 +00:00
|
|
|
@test "shell integration disabled" {
|
2018-04-02 01:52:42 +00:00
|
|
|
run pyenv shell
|
|
|
|
assert_failure "pyenv: shell integration not enabled. Run \`pyenv init' for instructions."
|
2017-12-07 01:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shell integration enabled" {
|
2018-04-02 01:52:42 +00:00
|
|
|
eval "$(pyenv init -)"
|
|
|
|
run pyenv shell
|
|
|
|
assert_success "pyenv: no shell-specific version configured"
|
2017-12-07 01:29:48 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 16:48:22 +00:00
|
|
|
@test "no shell version" {
|
|
|
|
mkdir -p "${PYENV_TEST_DIR}/myproject"
|
|
|
|
cd "${PYENV_TEST_DIR}/myproject"
|
|
|
|
echo "1.2.3" > .python-version
|
|
|
|
PYENV_VERSION="" run pyenv-sh-shell
|
|
|
|
assert_failure "pyenv: no shell-specific version configured"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shell version" {
|
|
|
|
PYENV_SHELL=bash PYENV_VERSION="1.2.3" run pyenv-sh-shell
|
|
|
|
assert_success 'echo "$PYENV_VERSION"'
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shell version (fish)" {
|
|
|
|
PYENV_SHELL=fish PYENV_VERSION="1.2.3" run pyenv-sh-shell
|
|
|
|
assert_success 'echo "$PYENV_VERSION"'
|
|
|
|
}
|
|
|
|
|
2016-11-25 19:24:16 +00:00
|
|
|
@test "shell revert" {
|
2017-06-05 13:02:24 +00:00
|
|
|
PYENV_SHELL=bash run pyenv-sh-shell -
|
2016-11-25 19:24:16 +00:00
|
|
|
assert_success
|
2017-06-05 13:02:24 +00:00
|
|
|
assert_line 0 'if [ -n "${PYENV_VERSION_OLD+x}" ]; then'
|
2016-11-25 19:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shell revert (fish)" {
|
2017-06-05 13:02:24 +00:00
|
|
|
PYENV_SHELL=fish run pyenv-sh-shell -
|
2016-11-25 19:24:16 +00:00
|
|
|
assert_success
|
2017-06-05 13:02:24 +00:00
|
|
|
assert_line 0 'if set -q PYENV_VERSION_OLD'
|
2016-11-25 19:24:16 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 16:48:22 +00:00
|
|
|
@test "shell unset" {
|
|
|
|
PYENV_SHELL=bash run pyenv-sh-shell --unset
|
2016-11-25 19:24:16 +00:00
|
|
|
assert_success
|
2016-01-12 19:03:50 +00:00
|
|
|
assert_output <<OUT
|
2021-01-16 12:38:31 +00:00
|
|
|
PYENV_VERSION_OLD="\${PYENV_VERSION-}"
|
2017-06-05 13:02:24 +00:00
|
|
|
unset PYENV_VERSION
|
2016-01-12 19:03:50 +00:00
|
|
|
OUT
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shell unset (fish)" {
|
|
|
|
PYENV_SHELL=fish run pyenv-sh-shell --unset
|
2016-11-25 19:24:16 +00:00
|
|
|
assert_success
|
2016-01-12 19:03:50 +00:00
|
|
|
assert_output <<OUT
|
2017-06-05 13:02:24 +00:00
|
|
|
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
|
|
|
set -e PYENV_VERSION
|
2016-01-12 19:03:50 +00:00
|
|
|
OUT
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shell change invalid version" {
|
|
|
|
run pyenv-sh-shell 1.2.3
|
|
|
|
assert_failure
|
|
|
|
assert_output <<SH
|
|
|
|
pyenv: version \`1.2.3' not installed
|
|
|
|
false
|
|
|
|
SH
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shell change version" {
|
|
|
|
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
|
|
|
PYENV_SHELL=bash run pyenv-sh-shell 1.2.3
|
2016-11-25 19:24:16 +00:00
|
|
|
assert_success
|
2016-01-12 19:03:50 +00:00
|
|
|
assert_output <<OUT
|
2021-01-16 12:38:31 +00:00
|
|
|
PYENV_VERSION_OLD="\${PYENV_VERSION-}"
|
2017-06-05 13:02:24 +00:00
|
|
|
export PYENV_VERSION="1.2.3"
|
2016-01-12 19:03:50 +00:00
|
|
|
OUT
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shell change version (fish)" {
|
|
|
|
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
|
|
|
PYENV_SHELL=fish run pyenv-sh-shell 1.2.3
|
2016-11-25 19:24:16 +00:00
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
2017-06-05 13:02:24 +00:00
|
|
|
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
|
|
|
set -gx PYENV_VERSION "1.2.3"
|
2016-11-25 19:24:16 +00:00
|
|
|
OUT
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|