2014-01-03 01:48:22 +09:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
2017-12-07 02:29:48 +01: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 02:29:48 +01: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 02:29:48 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-03 01:48:22 +09: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"'
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 04:33:19 +02:00
|
|
|
@test "shell version (pwsh)" {
|
|
|
|
|
PYENV_SHELL=pwsh PYENV_VERSION="1.2.3" run pyenv-sh-shell
|
|
|
|
|
assert_success 'echo "$PYENV_VERSION"'
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 20:24:16 +01:00
|
|
|
@test "shell revert" {
|
2017-06-05 15:02:24 +02:00
|
|
|
PYENV_SHELL=bash run pyenv-sh-shell -
|
2016-11-25 20:24:16 +01:00
|
|
|
assert_success
|
2017-06-05 15:02:24 +02:00
|
|
|
assert_line 0 'if [ -n "${PYENV_VERSION_OLD+x}" ]; then'
|
2016-11-25 20:24:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "shell revert (fish)" {
|
2017-06-05 15:02:24 +02:00
|
|
|
PYENV_SHELL=fish run pyenv-sh-shell -
|
2016-11-25 20:24:16 +01:00
|
|
|
assert_success
|
2017-06-05 15:02:24 +02:00
|
|
|
assert_line 0 'if set -q PYENV_VERSION_OLD'
|
2016-11-25 20:24:16 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-21 04:33:19 +02:00
|
|
|
@test "shell revert (pwsh)" {
|
|
|
|
|
PYENV_SHELL=pwsh run pyenv-sh-shell -
|
|
|
|
|
assert_success
|
|
|
|
|
assert_line 0 'if ( Get-Item -Path Env:\PYENV_VERSION* ) {'
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-03 01:48:22 +09:00
|
|
|
@test "shell unset" {
|
|
|
|
|
PYENV_SHELL=bash run pyenv-sh-shell --unset
|
2016-11-25 20:24:16 +01:00
|
|
|
assert_success
|
2016-01-12 11:03:50 -08:00
|
|
|
assert_output <<OUT
|
2021-01-16 14:38:31 +02:00
|
|
|
PYENV_VERSION_OLD="\${PYENV_VERSION-}"
|
2017-06-05 15:02:24 +02:00
|
|
|
unset PYENV_VERSION
|
2016-01-12 11:03:50 -08:00
|
|
|
OUT
|
2014-01-03 01:48:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "shell unset (fish)" {
|
|
|
|
|
PYENV_SHELL=fish run pyenv-sh-shell --unset
|
2016-11-25 20:24:16 +01:00
|
|
|
assert_success
|
2016-01-12 11:03:50 -08:00
|
|
|
assert_output <<OUT
|
2017-06-05 15:02:24 +02:00
|
|
|
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
|
|
|
|
set -e PYENV_VERSION
|
2016-01-12 11:03:50 -08:00
|
|
|
OUT
|
2014-01-03 01:48:22 +09:00
|
|
|
}
|
|
|
|
|
|
2025-12-21 04:33:19 +02:00
|
|
|
@test "shell unset (pwsh)" {
|
|
|
|
|
PYENV_SHELL=pwsh run pyenv-sh-shell --unset
|
|
|
|
|
assert_success
|
|
|
|
|
assert_output <<OUT
|
|
|
|
|
\$Env:PYENV_VERSION, \$Env:PYENV_VERSION_OLD = \$null, \$Env:PYENV_VERSION
|
|
|
|
|
OUT
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-03 01:48:22 +09: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 20:24:16 +01:00
|
|
|
assert_success
|
2016-01-12 11:03:50 -08:00
|
|
|
assert_output <<OUT
|
2021-01-16 14:38:31 +02:00
|
|
|
PYENV_VERSION_OLD="\${PYENV_VERSION-}"
|
2017-06-05 15:02:24 +02:00
|
|
|
export PYENV_VERSION="1.2.3"
|
2016-01-12 11:03:50 -08:00
|
|
|
OUT
|
2014-01-03 01:48:22 +09: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 20:24:16 +01:00
|
|
|
assert_success
|
|
|
|
|
assert_output <<OUT
|
2017-06-05 15:02:24 +02:00
|
|
|
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
|
|
|
|
set -gx PYENV_VERSION "1.2.3"
|
2016-11-25 20:24:16 +01:00
|
|
|
OUT
|
2014-01-03 01:48:22 +09:00
|
|
|
}
|
2025-12-21 04:33:19 +02:00
|
|
|
|
|
|
|
|
@test "shell change version (pwsh)" {
|
|
|
|
|
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
|
|
|
|
PYENV_SHELL=pwsh run pyenv-sh-shell 1.2.3
|
|
|
|
|
assert_success
|
|
|
|
|
assert_output <<OUT
|
|
|
|
|
\$Env:PYENV_VERSION, \$Env:PYENV_VERSION_OLD = "1.2.3", \$Env:PYENV_VERSION
|
|
|
|
|
OUT
|
|
|
|
|
}
|