2014-01-02 11:48:22 -05:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
@test "creates shims and versions directories" {
|
|
|
|
assert [ ! -d "${PYENV_ROOT}/shims" ]
|
|
|
|
assert [ ! -d "${PYENV_ROOT}/versions" ]
|
|
|
|
run pyenv-init -
|
|
|
|
assert_success
|
|
|
|
assert [ -d "${PYENV_ROOT}/shims" ]
|
|
|
|
assert [ -d "${PYENV_ROOT}/versions" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto rehash" {
|
|
|
|
run pyenv-init -
|
|
|
|
assert_success
|
2015-11-20 23:13:52 -05:00
|
|
|
assert_line "command pyenv rehash 2>/dev/null"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "setup shell completions" {
|
|
|
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
|
|
|
run pyenv-init - bash
|
|
|
|
assert_success
|
2014-11-30 10:20:53 -05:00
|
|
|
assert_line "source '${root}/test/../libexec/../completions/pyenv.bash'"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "detect parent shell" {
|
|
|
|
SHELL=/bin/false run pyenv-init -
|
|
|
|
assert_success
|
|
|
|
assert_line "export PYENV_SHELL=bash"
|
|
|
|
}
|
|
|
|
|
2015-12-24 06:29:35 -05:00
|
|
|
@test "detect parent shell from script" {
|
2016-03-01 20:39:52 -05:00
|
|
|
mkdir -p "$PYENV_TEST_DIR"
|
|
|
|
cd "$PYENV_TEST_DIR"
|
2015-12-24 06:29:35 -05:00
|
|
|
cat > myscript.sh <<OUT
|
|
|
|
#!/bin/sh
|
2019-04-23 10:23:33 -04:00
|
|
|
eval "\$(pyenv-init -)"
|
2016-03-01 20:39:52 -05:00
|
|
|
echo \$PYENV_SHELL
|
2015-12-24 06:29:35 -05:00
|
|
|
OUT
|
|
|
|
chmod +x myscript.sh
|
2021-03-23 17:45:32 -04:00
|
|
|
run ./myscript.sh
|
2015-12-24 06:29:35 -05:00
|
|
|
assert_success "sh"
|
|
|
|
}
|
|
|
|
|
2014-01-02 11:48:22 -05:00
|
|
|
@test "setup shell completions (fish)" {
|
|
|
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
|
|
|
run pyenv-init - fish
|
|
|
|
assert_success
|
2017-06-05 09:02:24 -04:00
|
|
|
assert_line "source '${root}/test/../libexec/../completions/pyenv.fish'"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "fish instructions" {
|
|
|
|
run pyenv-init fish
|
|
|
|
assert [ "$status" -eq 1 ]
|
2020-10-01 21:28:29 -04:00
|
|
|
assert_line 'pyenv init - | source'
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "option to skip rehash" {
|
|
|
|
run pyenv-init - --no-rehash
|
|
|
|
assert_success
|
|
|
|
refute_line "pyenv rehash 2>/dev/null"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds shims to PATH" {
|
2014-01-02 14:58:29 -05:00
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
2021-05-03 21:30:52 -04:00
|
|
|
run pyenv-init --path bash
|
2014-01-02 11:48:22 -05:00
|
|
|
assert_success
|
|
|
|
assert_line 0 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds shims to PATH (fish)" {
|
2014-01-02 14:58:29 -05:00
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
2021-05-03 21:30:52 -04:00
|
|
|
run pyenv-init --path fish
|
2014-01-02 11:48:22 -05:00
|
|
|
assert_success
|
2017-06-05 09:02:24 -04:00
|
|
|
assert_line 0 "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
2015-04-19 18:00:04 -04:00
|
|
|
@test "can add shims to PATH more than once" {
|
2014-01-02 11:48:22 -05:00
|
|
|
export PATH="${PYENV_ROOT}/shims:$PATH"
|
2021-05-03 21:30:52 -04:00
|
|
|
run pyenv-init --path bash
|
2014-01-02 11:48:22 -05:00
|
|
|
assert_success
|
2014-11-30 10:20:53 -05:00
|
|
|
assert_line 0 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
2015-05-26 11:54:19 -04:00
|
|
|
@test "can add shims to PATH more than once (fish)" {
|
2014-01-02 11:48:22 -05:00
|
|
|
export PATH="${PYENV_ROOT}/shims:$PATH"
|
2021-05-03 21:30:52 -04:00
|
|
|
run pyenv-init --path fish
|
2014-01-02 11:48:22 -05:00
|
|
|
assert_success
|
2017-06-05 09:02:24 -04:00
|
|
|
assert_line 0 "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
2014-11-30 10:20:53 -05:00
|
|
|
|
|
|
|
@test "outputs sh-compatible syntax" {
|
|
|
|
run pyenv-init - bash
|
|
|
|
assert_success
|
|
|
|
assert_line ' case "$command" in'
|
|
|
|
|
|
|
|
run pyenv-init - zsh
|
|
|
|
assert_success
|
|
|
|
assert_line ' case "$command" in'
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "outputs fish-specific syntax (fish)" {
|
|
|
|
run pyenv-init - fish
|
|
|
|
assert_success
|
|
|
|
assert_line ' switch "$command"'
|
|
|
|
refute_line ' case "$command" in'
|
|
|
|
}
|