mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Handle case where pyenv-commands --sh
returns nothing (#2908)
In exceptional cases (custom installation, malfunctions elsewhere), `pyenv-commands --sh` may return nothing. In non-Fish, this would cause "syntax error near unexpected token `)'" in `pyenv()`. Bash does not allow to specify a `case` option that would never match. This works around it by defaulting to `/`. Commands, being filenames, can never match it. In Fish, nothing needs to be done: it apparently does interpret a `case` without argument as one that never matches.
This commit is contained in:
parent
f9a2bb81b6
commit
02e1d4a293
2 changed files with 31 additions and 1 deletions
|
@ -297,7 +297,7 @@ EOS
|
|||
fi
|
||||
|
||||
case "\$command" in
|
||||
${commands[*]})
|
||||
${commands[*]:-/})
|
||||
eval "\$(pyenv "sh-\$command" "\$@")"
|
||||
;;
|
||||
*)
|
||||
|
|
|
@ -2,6 +2,18 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
export PATH="${PYENV_TEST_DIR}/bin:$PATH"
|
||||
}
|
||||
|
||||
create_executable() {
|
||||
local name="$1"
|
||||
local bin="${PYENV_TEST_DIR}/bin"
|
||||
mkdir -p "$bin"
|
||||
sed -Ee '1s/^ +//' > "${bin}/$name"
|
||||
chmod +x "${bin}/$name"
|
||||
}
|
||||
|
||||
@test "creates shims and versions directories" {
|
||||
assert [ ! -d "${PYENV_ROOT}/shims" ]
|
||||
assert [ ! -d "${PYENV_ROOT}/versions" ]
|
||||
|
@ -167,6 +179,24 @@ echo "\$PATH"
|
|||
assert_line ' case "$command" in'
|
||||
}
|
||||
|
||||
@test "outputs sh-compatible case syntax" {
|
||||
create_executable pyenv-commands <<!
|
||||
#!$BASH
|
||||
echo -e 'activate\ndeactivate\nrehash\nshell'
|
||||
!
|
||||
run pyenv-init - bash
|
||||
assert_success
|
||||
assert_line ' activate|deactivate|rehash|shell)'
|
||||
|
||||
create_executable pyenv-commands <<!
|
||||
#!$BASH
|
||||
echo
|
||||
!
|
||||
run pyenv-init - bash
|
||||
assert_success
|
||||
assert_line ' /)'
|
||||
}
|
||||
|
||||
@test "outputs fish-specific syntax (fish)" {
|
||||
run pyenv-init - fish
|
||||
assert_success
|
||||
|
|
Loading…
Reference in a new issue