#!/usr/bin/env bats load test_helper create_version() { mkdir -p "${PYENV_ROOT}/versions/$1" } create_alias() { mkdir -p "${PYENV_ROOT}/versions" ln -s "$2" "${PYENV_ROOT}/versions/$1" } setup() { mkdir -p "$PYENV_TEST_DIR" cd "$PYENV_TEST_DIR" } stub_system_python() { local stub="${PYENV_TEST_DIR}/bin/python" mkdir -p "$(dirname "$stub")" touch "$stub" && chmod +x "$stub" } create_executable() { local name="$1" local bin="${PYENV_TEST_DIR}/bin" mkdir -p "$bin" sed -Ee '1s/^ +//' > "${bin}/$name" chmod +x "${bin}/$name" } @test "no versions installed" { stub_system_python assert [ ! -d "${PYENV_ROOT}/versions" ] run pyenv-versions assert_success "* system (set by ${PYENV_ROOT}/version)" } @test "not even system python available" { PATH="$(path_without python python2 python3)" run pyenv-versions assert_failure assert_output "Warning: no Python detected on the system" } @test "bare output no versions installed" { assert [ ! -d "${PYENV_ROOT}/versions" ] run pyenv-versions --bare assert_success "" } @test "single version installed" { stub_system_python create_version "3.3" run pyenv-versions assert_success assert_output < "${PYENV_ROOT}/version" <<<"3.3.3" run pyenv-versions assert_success assert_output < ".python-version" <<<"3.3.3" run pyenv-versions assert_success assert_output < foo/bar OUT }