Procházet zdrojové kódy

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.
pull/2906/head
Alex Hedges před 6 měsíci
odevzdal GitHub
rodič
revize
02e1d4a293
V databázi nebyl nalezen žádný známý klíč pro tento podpis ID GPG klíče: B5690EEEBB952194
2 změnil soubory, kde provedl 31 přidání a 1 odebrání
  1. +1
    -1
      libexec/pyenv-init
  2. +30
    -0
      test/init.bats

+ 1
- 1
libexec/pyenv-init Zobrazit soubor

@ -297,7 +297,7 @@ EOS
fi
case "\$command" in
${commands[*]})
${commands[*]:-/})
eval "\$(pyenv "sh-\$command" "\$@")"
;;
*)

+ 30
- 0
test/init.bats Zobrazit soubor

@ -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

Načítá se…
Zrušit
Uložit