#!/usr/bin/env bats load test_helper create_executable() { local bin="${PYENV_ROOT}/versions/${1}/bin" mkdir -p "$bin" touch "${bin}/$2" chmod +x "${bin}/$2" } @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_executable "2.7" "python" create_executable "2.7" "fab" create_executable "3.4" "python" create_executable "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" assert [ -x "${PYENV_ROOT}/shims/python" ] } @test "sh-rehash in fish" { create_executable "3.4" "python" PYENV_SHELL=fish run pyenv-sh-rehash assert_success "" assert [ -x "${PYENV_ROOT}/shims/python" ] }