mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Add unit tests for pwsh
This commit is contained in:
parent
99c693df39
commit
11b615f709
3 changed files with 99 additions and 0 deletions
|
@ -63,6 +63,19 @@ OUT
|
||||||
assert_line 'pyenv init - | source'
|
assert_line 'pyenv init - | source'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "setup shell completions (pwsh)" {
|
||||||
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||||
|
run pyenv-init - pwsh
|
||||||
|
assert_success
|
||||||
|
assert_line "iex (gc ${root}/test/../libexec/../completions/pyenv.pwsh -Raw)"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "pwsh instructions" {
|
||||||
|
run pyenv-init pwsh
|
||||||
|
assert [ "$status" -eq 1 ]
|
||||||
|
assert_line 'iex ((pyenv init -) -join "`n")'
|
||||||
|
}
|
||||||
|
|
||||||
@test "shell detection for installer" {
|
@test "shell detection for installer" {
|
||||||
run pyenv-init --detect-shell
|
run pyenv-init --detect-shell
|
||||||
assert_success
|
assert_success
|
||||||
|
@ -89,6 +102,13 @@ OUT
|
||||||
assert_line "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
|
assert_line "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "adds shims to PATH (pwsh)" {
|
||||||
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
||||||
|
run pyenv-init - pwsh
|
||||||
|
assert_success
|
||||||
|
assert_line '$Env:PATH="'${PYENV_ROOT}'/shims:$Env:PATH"'
|
||||||
|
}
|
||||||
|
|
||||||
@test "removes existing shims from PATH" {
|
@test "removes existing shims from PATH" {
|
||||||
OLDPATH="$PATH"
|
OLDPATH="$PATH"
|
||||||
export PATH="${BATS_TEST_DIRNAME}/nonexistent:${PYENV_ROOT}/shims:$PATH"
|
export PATH="${BATS_TEST_DIRNAME}/nonexistent:${PYENV_ROOT}/shims:$PATH"
|
||||||
|
@ -113,6 +133,19 @@ echo "\$PATH"
|
||||||
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
|
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "removes existing shims from PATH (pwsh)" {
|
||||||
|
command -v pwsh >/dev/null || skip "-- pwsh not installed"
|
||||||
|
OLDPATH="$PATH"
|
||||||
|
export PATH="${BATS_TEST_DIRNAME}/nonexistent:${PYENV_ROOT}/shims:$PATH"
|
||||||
|
run pwsh -noni -c - <<!
|
||||||
|
\$Env:PATH="$PATH"
|
||||||
|
iex ((pyenv init -) -join "\`n")
|
||||||
|
echo "\$Env:PATH"
|
||||||
|
!
|
||||||
|
assert_success
|
||||||
|
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
|
||||||
|
}
|
||||||
|
|
||||||
@test "adds shims to PATH with --no-push-path if they're not on PATH" {
|
@test "adds shims to PATH with --no-push-path if they're not on PATH" {
|
||||||
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
||||||
run bash -e <<!
|
run bash -e <<!
|
||||||
|
@ -135,6 +168,18 @@ echo "\$PATH"
|
||||||
assert_output "${PYENV_ROOT}/shims:${PATH}"
|
assert_output "${PYENV_ROOT}/shims:${PATH}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "adds shims to PATH with --no-push-path if they're not on PATH (pwsh)" {
|
||||||
|
command -v pwsh >/dev/null || skip "-- pwsh not installed"
|
||||||
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
||||||
|
run pwsh -noni -c - <<!
|
||||||
|
\$Env:PATH="$PATH"
|
||||||
|
iex ((pyenv init - --no-push-path) -join "\`n")
|
||||||
|
echo "\$Env:PATH"
|
||||||
|
!
|
||||||
|
assert_success
|
||||||
|
assert_output "${PYENV_ROOT}/shims:${PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
@test "doesn't change PATH with --no-push-path if shims are already on PATH" {
|
@test "doesn't change PATH with --no-push-path if shims are already on PATH" {
|
||||||
export PATH="${BATS_TEST_DIRNAME}/../libexec:${PYENV_ROOT}/shims:/usr/bin:/bin:/usr/local/bin"
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:${PYENV_ROOT}/shims:/usr/bin:/bin:/usr/local/bin"
|
||||||
run bash -e <<!
|
run bash -e <<!
|
||||||
|
@ -157,6 +202,18 @@ echo "\$PATH"
|
||||||
assert_output "${PATH}"
|
assert_output "${PATH}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "doesn't change PATH with --no-push-path if shims are already on PATH (pwsh)" {
|
||||||
|
command -v pwsh >/dev/null || skip "-- pwsh not installed"
|
||||||
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:${PYENV_ROOT}/shims:/bin:/usr/local/bin"
|
||||||
|
run pwsh -noni -c - <<!
|
||||||
|
\$Env:PATH="$PATH"
|
||||||
|
iex ((pyenv init - --no-push-path) -join "\`n")
|
||||||
|
echo "\$Env:PATH"
|
||||||
|
!
|
||||||
|
assert_success
|
||||||
|
assert_output "${PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
@test "outputs sh-compatible syntax" {
|
@test "outputs sh-compatible syntax" {
|
||||||
run pyenv-init - bash
|
run pyenv-init - bash
|
||||||
assert_success
|
assert_success
|
||||||
|
@ -173,3 +230,10 @@ echo "\$PATH"
|
||||||
assert_line ' switch "$command"'
|
assert_line ' switch "$command"'
|
||||||
refute_line ' case "$command" in'
|
refute_line ' case "$command" in'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "outputs pwsh-specific syntax (pwsh)" {
|
||||||
|
run pyenv-init - pwsh
|
||||||
|
assert_success
|
||||||
|
refute_line ' switch "$command"'
|
||||||
|
refute_line ' case "$command" in'
|
||||||
|
}
|
||||||
|
|
|
@ -120,3 +120,10 @@ SH
|
||||||
assert_success ""
|
assert_success ""
|
||||||
assert [ -x "${PYENV_ROOT}/shims/python" ]
|
assert [ -x "${PYENV_ROOT}/shims/python" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "sh-rehash in pwsh" {
|
||||||
|
create_executable "3.4" "python"
|
||||||
|
PYENV_SHELL=pwsh run pyenv-sh-rehash
|
||||||
|
assert_success ""
|
||||||
|
assert [ -x "${PYENV_ROOT}/shims/python" ]
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,11 @@ load test_helper
|
||||||
assert_success 'echo "$PYENV_VERSION"'
|
assert_success 'echo "$PYENV_VERSION"'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "shell version (pwsh)" {
|
||||||
|
PYENV_SHELL=pwsh PYENV_VERSION="1.2.3" run pyenv-sh-shell
|
||||||
|
assert_success 'echo "$PYENV_VERSION"'
|
||||||
|
}
|
||||||
|
|
||||||
@test "shell revert" {
|
@test "shell revert" {
|
||||||
PYENV_SHELL=bash run pyenv-sh-shell -
|
PYENV_SHELL=bash run pyenv-sh-shell -
|
||||||
assert_success
|
assert_success
|
||||||
|
@ -43,6 +48,12 @@ load test_helper
|
||||||
assert_line 0 'if set -q PYENV_VERSION_OLD'
|
assert_line 0 'if set -q PYENV_VERSION_OLD'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "shell revert (pwsh)" {
|
||||||
|
PYENV_SHELL=pwsh run pyenv-sh-shell -
|
||||||
|
assert_success
|
||||||
|
assert_line 0 'if set -q PYENV_VERSION_OLD'
|
||||||
|
}
|
||||||
|
|
||||||
@test "shell unset" {
|
@test "shell unset" {
|
||||||
PYENV_SHELL=bash run pyenv-sh-shell --unset
|
PYENV_SHELL=bash run pyenv-sh-shell --unset
|
||||||
assert_success
|
assert_success
|
||||||
|
@ -61,6 +72,14 @@ set -e PYENV_VERSION
|
||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
||||||
|
}
|
||||||
|
|
||||||
@test "shell change invalid version" {
|
@test "shell change invalid version" {
|
||||||
run pyenv-sh-shell 1.2.3
|
run pyenv-sh-shell 1.2.3
|
||||||
assert_failure
|
assert_failure
|
||||||
|
@ -89,3 +108,12 @@ set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
||||||
set -gx PYENV_VERSION "1.2.3"
|
set -gx PYENV_VERSION "1.2.3"
|
||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue