2014-01-02 16:48:22 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
2024-02-25 21:07:52 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2014-01-02 16:48:22 +00:00
|
|
|
@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-21 04:13:52 +00:00
|
|
|
assert_line "command pyenv rehash 2>/dev/null"
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
2022-05-01 22:17:59 +00:00
|
|
|
@test "auto rehash for --path" {
|
|
|
|
run pyenv-init --path
|
|
|
|
assert_success
|
|
|
|
assert_line "command pyenv rehash 2>/dev/null"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-02 16:48:22 +00:00
|
|
|
@test "setup shell completions" {
|
|
|
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
|
|
|
run pyenv-init - bash
|
|
|
|
assert_success
|
2014-11-30 15:20:53 +00:00
|
|
|
assert_line "source '${root}/test/../libexec/../completions/pyenv.bash'"
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "detect parent shell" {
|
|
|
|
SHELL=/bin/false run pyenv-init -
|
|
|
|
assert_success
|
|
|
|
assert_line "export PYENV_SHELL=bash"
|
|
|
|
}
|
|
|
|
|
2015-12-24 11:29:35 +00:00
|
|
|
@test "detect parent shell from script" {
|
2016-03-02 01:39:52 +00:00
|
|
|
mkdir -p "$PYENV_TEST_DIR"
|
|
|
|
cd "$PYENV_TEST_DIR"
|
2015-12-24 11:29:35 +00:00
|
|
|
cat > myscript.sh <<OUT
|
|
|
|
#!/bin/sh
|
2019-04-23 14:23:33 +00:00
|
|
|
eval "\$(pyenv-init -)"
|
2016-03-02 01:39:52 +00:00
|
|
|
echo \$PYENV_SHELL
|
2015-12-24 11:29:35 +00:00
|
|
|
OUT
|
|
|
|
chmod +x myscript.sh
|
2021-03-23 21:45:32 +00:00
|
|
|
run ./myscript.sh
|
2015-12-24 11:29:35 +00:00
|
|
|
assert_success "sh"
|
|
|
|
}
|
|
|
|
|
2014-01-02 16:48:22 +00:00
|
|
|
@test "setup shell completions (fish)" {
|
|
|
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
|
|
|
run pyenv-init - fish
|
|
|
|
assert_success
|
2017-06-05 13:02:24 +00:00
|
|
|
assert_line "source '${root}/test/../libexec/../completions/pyenv.fish'"
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "fish instructions" {
|
|
|
|
run pyenv-init fish
|
|
|
|
assert [ "$status" -eq 1 ]
|
2022-04-03 22:08:49 +00:00
|
|
|
assert_line 'pyenv init - | source'
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
2022-12-24 23:35:03 +00:00
|
|
|
@test "shell detection for installer" {
|
|
|
|
run pyenv-init --detect-shell
|
|
|
|
assert_success
|
|
|
|
assert_line "PYENV_SHELL_DETECT=bash"
|
|
|
|
}
|
|
|
|
|
2014-01-02 16:48:22 +00: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 19:58:29 +00:00
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
2022-04-03 22:08:49 +00:00
|
|
|
run pyenv-init - bash
|
2014-01-02 16:48:22 +00:00
|
|
|
assert_success
|
2022-04-03 22:08:49 +00:00
|
|
|
assert_line 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds shims to PATH (fish)" {
|
2014-01-02 19:58:29 +00:00
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
2022-04-03 22:08:49 +00:00
|
|
|
run pyenv-init - fish
|
2014-01-02 16:48:22 +00:00
|
|
|
assert_success
|
2022-04-03 22:08:49 +00:00
|
|
|
assert_line "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 22:08:49 +00:00
|
|
|
@test "removes existing shims from PATH" {
|
|
|
|
OLDPATH="$PATH"
|
|
|
|
export PATH="${BATS_TEST_DIRNAME}/nonexistent:${PYENV_ROOT}/shims:$PATH"
|
|
|
|
run bash -e <<!
|
|
|
|
eval "\$(pyenv-init -)"
|
|
|
|
echo "\$PATH"
|
|
|
|
!
|
2014-01-02 16:48:22 +00:00
|
|
|
assert_success
|
2022-04-03 22:08:49 +00:00
|
|
|
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 22:08:49 +00:00
|
|
|
@test "removes existing shims from PATH (fish)" {
|
|
|
|
command -v fish >/dev/null || skip "-- fish not installed"
|
|
|
|
OLDPATH="$PATH"
|
|
|
|
export PATH="${BATS_TEST_DIRNAME}/nonexistent:${PYENV_ROOT}/shims:$PATH"
|
|
|
|
run fish <<!
|
|
|
|
set -x PATH "$PATH"
|
|
|
|
pyenv init - | source
|
|
|
|
echo "\$PATH"
|
|
|
|
!
|
2014-01-02 16:48:22 +00:00
|
|
|
assert_success
|
2022-04-03 22:08:49 +00:00
|
|
|
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
|
2014-01-02 16:48:22 +00:00
|
|
|
}
|
2014-11-30 15:20:53 +00:00
|
|
|
|
2022-11-18 21:01:59 +00:00
|
|
|
@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"
|
|
|
|
run bash -e <<!
|
|
|
|
eval "\$(pyenv-init - --no-push-path)"
|
|
|
|
echo "\$PATH"
|
|
|
|
!
|
|
|
|
assert_success
|
|
|
|
assert_output "${PYENV_ROOT}/shims:${PATH}"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds shims to PATH with --no-push-path if they're not on PATH (fish)" {
|
|
|
|
command -v fish >/dev/null || skip "-- fish not installed"
|
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
|
|
|
run fish <<!
|
|
|
|
set -x PATH "$PATH"
|
|
|
|
pyenv-init - --no-push-path| source
|
|
|
|
echo "\$PATH"
|
|
|
|
!
|
|
|
|
assert_success
|
|
|
|
assert_output "${PYENV_ROOT}/shims:${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"
|
|
|
|
run bash -e <<!
|
|
|
|
eval "\$(pyenv-init - --no-push-path)"
|
|
|
|
echo "\$PATH"
|
|
|
|
!
|
|
|
|
assert_success
|
|
|
|
assert_output "${PATH}"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "doesn't change PATH with --no-push-path if shims are already on PATH (fish)" {
|
|
|
|
command -v fish >/dev/null || skip "-- fish not installed"
|
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:${PYENV_ROOT}/shims:/bin:/usr/local/bin"
|
|
|
|
run fish <<!
|
|
|
|
set -x PATH "$PATH"
|
|
|
|
pyenv-init - --no-push-path| source
|
|
|
|
echo "\$PATH"
|
|
|
|
!
|
|
|
|
assert_success
|
|
|
|
assert_output "${PATH}"
|
|
|
|
}
|
|
|
|
|
2014-11-30 15:20:53 +00: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'
|
|
|
|
}
|
|
|
|
|
2024-02-25 21:07:52 +00:00
|
|
|
@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 ' /)'
|
|
|
|
}
|
|
|
|
|
2014-11-30 15:20:53 +00:00
|
|
|
@test "outputs fish-specific syntax (fish)" {
|
|
|
|
run pyenv-init - fish
|
|
|
|
assert_success
|
|
|
|
assert_line ' switch "$command"'
|
|
|
|
refute_line ' case "$command" in'
|
|
|
|
}
|