#!/usr/bin/env bats load test_helper @test "empty rehash" { assert [ ! -d "${PYENV_ROOT}/shims" ] run pyenv-rehash assert_success "" assert [ -d "${PYENV_ROOT}/shims" ] rmdir "${PYENV_ROOT}/shims" } @test "non-writable shims directory" { mkdir -p "${PYENV_ROOT}/shims" chmod -w "${PYENV_ROOT}/shims" run pyenv-rehash assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims isn't writable" } @test "rehash in progress" { export PYENV_REHASH_TIMEOUT=1 mkdir -p "${PYENV_ROOT}/shims" touch "${PYENV_ROOT}/shims/.pyenv-shim" run pyenv-rehash assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims/.pyenv-shim exists" } @test "wait until lock acquisition" { export PYENV_REHASH_TIMEOUT=5 mkdir -p "${PYENV_ROOT}/shims" touch "${PYENV_ROOT}/shims/.pyenv-shim" bash -c "sleep 1 && rm -f ${PYENV_ROOT}/shims/.pyenv-shim" & run pyenv-rehash assert_success } @test "creates shims" { create_alt_executable_in_version "2.7" "python" create_alt_executable_in_version "2.7" "fab" create_alt_executable_in_version "3.4" "python" create_alt_executable_in_version "3.4" "py.test" assert [ ! -e "${PYENV_ROOT}/shims/fab" ] assert [ ! -e "${PYENV_ROOT}/shims/python" ] assert [ ! -e "${PYENV_ROOT}/shims/py.test" ] run pyenv-rehash assert_success "" run ls "${PYENV_ROOT}/shims" assert_success assert_output </dev/null || true" } @test "sh-rehash in bash (integration)" { create_alt_executable_in_version "3.4" "python" PYENV_SHELL=bash run eval "$(pyenv-sh-rehash)" assert_success assert [ -x "${PYENV_ROOT}/shims/python" ] } @test "sh-rehash in fish" { create_alt_executable_in_version "3.4" "python" PYENV_SHELL=fish run pyenv-sh-rehash assert_success "command pyenv rehash" } @test "sh-rehash in fish (integration)" { command -v fish >/dev/null || skip "-- fish not installed" create_alt_executable_in_version "3.4" "python" PYENV_SHELL=fish fish -Nc "source (pyenv-sh-rehash | psub)" assert_success assert [ -x "${PYENV_ROOT}/shims/python" ] } @test "sh-rehash in pwsh" { create_alt_executable_in_version "3.4" "python" PYENV_SHELL=pwsh run pyenv-sh-rehash assert_success "& (get-command pyenv -commandtype application) rehash" } @test "sh-rehash in pwsh (integration)" { command -v pwsh >/dev/null || skip "-- pwsh not installed" assert [ ! -x "${PYENV_ROOT}/shims/python" ] create_alt_executable_in_version "3.4" "python" run pwsh -nop -c -<<'!' $ErrorActionPreference = "Stop" $PSNativeCommandUseErrorActionPreference = $true iex ((& pyenv init - pwsh) -join "`n") & pyenv rehash ! assert_success "" assert [ -x "${PYENV_ROOT}/shims/python" ] } @test "shim sets _PYENV_SHIM_PATH when linked from elsewhere" { export PYENV_VERSION="custom" create_alt_executable python3 #must stub pyenv before rehash 'cuz the path is hardcoded into shims create_stub pyenv <