diff --git a/plugins/python-build/test/arguments.bats b/plugins/python-build/test/arguments.bats index 965e5e43..55dfeff7 100644 --- a/plugins/python-build/test/arguments.bats +++ b/plugins/python-build/test/arguments.bats @@ -4,7 +4,7 @@ load test_helper @test "not enough arguments for python-build" { # use empty inline definition so nothing gets built anyway - local definition="${TMP}/build-definition" + local definition="${BATS_TEST_TMPDIR}/build-definition" echo '' > "$definition" run python-build "$definition" @@ -14,10 +14,10 @@ load test_helper @test "extra arguments for python-build" { # use empty inline definition so nothing gets built anyway - local definition="${TMP}/build-definition" + local definition="${BATS_TEST_TMPDIR}/build-definition" echo '' > "$definition" - run python-build "$definition" "${TMP}/install" "" + run python-build "$definition" "${BATS_TEST_TMPDIR}/install" "" assert_failure assert_output_contains 'Usage: python-build' } diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index b0c02aa9..300dbd7d 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -1,13 +1,13 @@ #!/usr/bin/env bats load test_helper -export PYTHON_BUILD_CACHE_PATH="$TMP/cache" -export MAKE=make -export MAKE_OPTS="-j 2" -export CC=cc -export -n PYTHON_CONFIGURE_OPTS +_setup() { + export PYTHON_BUILD_CACHE_PATH="$BATS_TEST_TMPDIR/cache" + export MAKE=make + export MAKE_OPTS="-j 2" + export CC=cc + export -n PYTHON_CONFIGURE_OPTS -setup() { mkdir -p "$INSTALL_ROOT" stub md5 false stub curl false @@ -74,11 +74,11 @@ assert_build_log() { unstub make assert_build_log <> build.log' - TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml <<<"" + TMPDIR="$BATS_TEST_TMPDIR" install_fixture --patch definitions/needs-yaml <<<"" assert_success unstub uname @@ -146,12 +146,12 @@ OUT unstub patch assert_build_log <> build.log' - TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml <<<"diff --git a/script.py" + TMPDIR="$BATS_TEST_TMPDIR" install_fixture --patch definitions/needs-yaml <<<"diff --git a/script.py" assert_success unstub uname @@ -176,12 +176,12 @@ OUT unstub patch assert_build_log <>"$tcl_tk_libdir/lib/tclConfig.sh" @@ -777,8 +777,8 @@ DEF unstub make assert_build_log <> build.log' stub_make_install - export PYTHON_CONFIGURE="${TMP}/custom-configure" + export PYTHON_CONFIGURE="${BATS_TEST_TMPDIR}/custom-configure" run_inline_definition < "${TMP}/definitions/2.7.8-test" - mkdir -p "${TMP}/other" - echo false > "${TMP}/other/2.7.8-test" - run python-build "2.7.8-test" "${TMP}/install" + export PYTHON_BUILD_DEFINITIONS="${BATS_TEST_TMPDIR}/definitions:${BATS_TEST_TMPDIR}/other" + mkdir -p "${BATS_TEST_TMPDIR}/definitions" + echo true > "${BATS_TEST_TMPDIR}/definitions/2.7.8-test" + mkdir -p "${BATS_TEST_TMPDIR}/other" + echo false > "${BATS_TEST_TMPDIR}/other/2.7.8-test" + run python-build "2.7.8-test" "${BATS_TEST_TMPDIR}/install" assert_success "" } @test "installing nonexistent definition" { - run python-build "nonexistent" "${TMP}/install" + run python-build "nonexistent" "${BATS_TEST_TMPDIR}/install" assert [ "$status" -eq 2 ] assert_output "python-build: definition not found: nonexistent" } @test "sorting Python versions" { - export PYTHON_BUILD_ROOT="$TMP" + export PYTHON_BUILD_ROOT="$BATS_TEST_TMPDIR" mkdir -p "${PYTHON_BUILD_ROOT}/share/python-build" expected="2.7-dev 2.7 @@ -95,7 +95,7 @@ jython-2.7-beta3" } @test "removing duplicate Python versions" { - export PYTHON_BUILD_ROOT="$TMP" + export PYTHON_BUILD_ROOT="$BATS_TEST_TMPDIR" export PYTHON_BUILD_DEFINITIONS="${PYTHON_BUILD_ROOT}/share/python-build" mkdir -p "$PYTHON_BUILD_DEFINITIONS" touch "${PYTHON_BUILD_DEFINITIONS}/2.7.8" diff --git a/plugins/python-build/test/fetch.bats b/plugins/python-build/test/fetch.bats index 0edd38aa..f36df53a 100644 --- a/plugins/python-build/test/fetch.bats +++ b/plugins/python-build/test/fetch.bats @@ -1,11 +1,10 @@ #!/usr/bin/env bats load test_helper -export PYTHON_BUILD_SKIP_MIRROR=1 -export PYTHON_BUILD_CACHE_PATH= - -setup() { - export PYTHON_BUILD_BUILD_PATH="${TMP}/source" +_setup() { + export PYTHON_BUILD_SKIP_MIRROR=1 + export PYTHON_BUILD_CACHE_PATH= + export PYTHON_BUILD_BUILD_PATH="${BATS_TEST_TMPDIR}/source" mkdir -p "${PYTHON_BUILD_BUILD_PATH}" } @@ -29,7 +28,7 @@ setup() { Downloading package-1.0.0.tar.gz... -> http://example.com/packages/package-1.0.0.tar.gz Installing package-1.0.0... -Installed package-1.0.0 to ${TMP}/install +Installed package-1.0.0 to ${BATS_TEST_TMPDIR}/install OUT unstub aria2c } @@ -44,7 +43,7 @@ DEF assert_output < "$definition" <<<"echo python-build" diff --git a/plugins/python-build/test/installer.bats b/plugins/python-build/test/installer.bats index dc04819a..6ce7c788 100644 --- a/plugins/python-build/test/installer.bats +++ b/plugins/python-build/test/installer.bats @@ -3,7 +3,7 @@ load test_helper @test "installs python-build into PREFIX" { - cd "$TMP" + cd "$BATS_TEST_TMPDIR" PREFIX="${PWD}/usr" run "${BATS_TEST_DIRNAME}/../install.sh" assert_success "" @@ -18,7 +18,7 @@ load test_helper } @test "build definitions don't have the executable bit" { - cd "$TMP" + cd "$BATS_TEST_TMPDIR" PREFIX="${PWD}/usr" run "${BATS_TEST_DIRNAME}/../install.sh" assert_success "" @@ -30,7 +30,7 @@ OUT } @test "overwrites old installation" { - cd "$TMP" + cd "$BATS_TEST_TMPDIR" mkdir -p bin share/python-build touch bin/python-build touch share/python-build/2.7.2 @@ -44,7 +44,7 @@ OUT } @test "unrelated files are untouched" { - cd "$TMP" + cd "$BATS_TEST_TMPDIR" mkdir -p bin share/bananas chmod g-w bin touch bin/bananas diff --git a/plugins/python-build/test/mirror.bats b/plugins/python-build/test/mirror.bats index c53b0096..bd761338 100644 --- a/plugins/python-build/test/mirror.bats +++ b/plugins/python-build/test/mirror.bats @@ -1,10 +1,12 @@ #!/usr/bin/env bats load test_helper -export PYTHON_BUILD_SKIP_MIRROR= -export PYTHON_BUILD_CACHE_PATH= -export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com +_setup() { + export PYTHON_BUILD_SKIP_MIRROR= + export PYTHON_BUILD_CACHE_PATH= + export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com +} @test "package URL without checksum bypasses mirror" { stub shasum true diff --git a/plugins/python-build/test/pyenv.bats b/plugins/python-build/test/pyenv.bats index 0108bfc1..f3b3c617 100644 --- a/plugins/python-build/test/pyenv.bats +++ b/plugins/python-build/test/pyenv.bats @@ -1,9 +1,9 @@ #!/usr/bin/env bats load test_helper -export PYENV_ROOT="${TMP}/pyenv" -setup() { +_setup() { + export PYENV_ROOT="${BATS_TEST_TMPDIR}/pyenv" stub pyenv-hooks 'install : true' stub pyenv-rehash true } @@ -39,8 +39,8 @@ stub_python_build() { run pyenv-install 3.4.1 3.4.2 assert_success assert_output < "$definition" run python-build "$definition" "${1:-$INSTALL_ROOT}" } @@ -118,12 +117,12 @@ run_inline_definition_with_name() { stub uname '-s : echo Linux' stub uname '-s : echo Linux' - TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null + TMPDIR="$BATS_TEST_TMPDIR" install_tmp_fixture definitions/vanilla-python < /dev/null assert_success assert_build_log <> "${INSTALL_ROOT}/build.log" OUT chmod +x "${INSTALL_ROOT}/bin/python" - PYTHON_MAKE_INSTALL_TARGET="" TMPDIR="$TMP" run_inline_definition <> "${INSTALL_ROOT}/build.log" OUT chmod +x "${INSTALL_ROOT}/bin/python" - PYTHON_MAKE_INSTALL_TARGET="altinstall" TMPDIR="$TMP" run_inline_definition <> build.log" \ " : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'" - PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null + PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" TMPDIR="$BATS_TEST_TMPDIR" install_tmp_fixture definitions/vanilla-python < /dev/null assert_success assert_build_log <>"${!_STUB_LOG}"; fi [ -e "${!_STUB_PLAN}" ] || exit 1 -[ -n "${!_STUB_RUN}" ] || eval "${_STUB_RUN}"="${TMPDIR}/${program}-stub-run" +[ -n "${!_STUB_RUN}" ] || eval "${_STUB_RUN}"="${BATS_TEST_TMPDIR}/${program}-stub-run" # Initialize or load the stub run information. diff --git a/plugins/python-build/test/test_helper.bash b/plugins/python-build/test/test_helper.bash index a51e7d67..82321e58 100644 --- a/plugins/python-build/test/test_helper.bash +++ b/plugins/python-build/test/test_helper.bash @@ -1,19 +1,18 @@ -export TMP="$BATS_TEST_DIRNAME/tmp" -export PYTHON_BUILD_CURL_OPTS= -export PYTHON_BUILD_HTTP_CLIENT="curl" +setup() { + export PYTHON_BUILD_CURL_OPTS= + export PYTHON_BUILD_HTTP_CLIENT="curl" -if [ "$FIXTURE_ROOT" != "$BATS_TEST_DIRNAME/fixtures" ]; then - export FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures" - export INSTALL_ROOT="$TMP/install" - PATH="/usr/bin:/bin:/usr/sbin:/sbin" - PATH="/usr/local/bin:$PATH" - PATH="$BATS_TEST_DIRNAME/../bin:$PATH" - PATH="$TMP/bin:$PATH" + export FIXTURE_ROOT="${BATS_TEST_DIRNAME}/fixtures" + export INSTALL_ROOT="${BATS_TEST_TMPDIR}/install" + PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" + PATH="${BATS_TEST_DIRNAME}/../bin:$PATH" + PATH="${BATS_TEST_TMPDIR}/bin:$PATH" export PATH -fi -teardown() { - rm -fr "${TMP:?}"/* + # If test specific setup exist, run it + if [[ $(type -t _setup) == function ]];then + _setup + fi } stub() { @@ -21,22 +20,22 @@ stub() { local prefix="$(echo "$program" | tr a-z- A-Z_)" shift - export "${prefix}_STUB_PLAN"="${TMP}/${program}-stub-plan" - export "${prefix}_STUB_RUN"="${TMP}/${program}-stub-run" - export "${prefix}_STUB_LOG"="${TMP}/${program}-stub-log" + export "${prefix}_STUB_PLAN"="${BATS_TEST_TMPDIR}/${program}-stub-plan" + export "${prefix}_STUB_RUN"="${BATS_TEST_TMPDIR}/${program}-stub-run" + export "${prefix}_STUB_LOG"="${BATS_TEST_TMPDIR}/${program}-stub-log" export "${prefix}_STUB_END"= - mkdir -p "${TMP}/bin" - cp "${BATS_TEST_DIRNAME}/stubs/stub" "${TMP}/bin/${program}" + mkdir -p "${BATS_TEST_TMPDIR}/bin" + cp "${BATS_TEST_DIRNAME}/stubs/stub" "${BATS_TEST_TMPDIR}/bin/${program}" - touch "${TMP}/${program}-stub-plan" - for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done + touch "${BATS_TEST_TMPDIR}/${program}-stub-plan" + for arg in "$@"; do printf "%s\n" "$arg" >> "${BATS_TEST_TMPDIR}/${program}-stub-plan"; done } unstub() { local program="$1" local prefix="$(echo "$program" | tr a-z- A-Z_)" - local path="${TMP}/bin/${program}" + local path="${BATS_TEST_TMPDIR}/bin/${program}" export "${prefix}_STUB_END"=1 @@ -44,12 +43,12 @@ unstub() { "$path" || STATUS="$?" rm -f "$path" - rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" + rm -f "${BATS_TEST_TMPDIR}/${program}-stub-plan" "${BATS_TEST_TMPDIR}/${program}-stub-run" return "$STATUS" } run_inline_definition() { - local definition="${TMP}/build-definition" + local definition="${BATS_TEST_TMPDIR}/build-definition" cat > "$definition" run python-build "$definition" "${1:-$INSTALL_ROOT}" } @@ -85,7 +84,7 @@ flunk() { { if [ "$#" -eq 0 ]; then cat - else echo "$@" fi - } | sed "s:${TMP}:\${TMP}:g" >&2 + } | sed "s:${BATS_TEST_TMPDIR}:\${BATS_TEST_TMPDIR}:g" >&2 return 1 } diff --git a/plugins/python-build/test/version.bats b/plugins/python-build/test/version.bats index e774abb5..8c9fc778 100644 --- a/plugins/python-build/test/version.bats +++ b/plugins/python-build/test/version.bats @@ -2,8 +2,8 @@ load test_helper -bats_bin="${BATS_TEST_DIRNAME}/../bin/python-build" -static_version="$(grep VERSION "$bats_bin" | head -n1 | cut -d'"' -f 2)" +python_build_bin="${BATS_TEST_DIRNAME}/../bin/python-build" +static_version="$(grep VERSION "$python_build_bin" | head -n1 | cut -d'"' -f 2)" @test "python-build static version" { stub git 'echo "ASPLODE" >&2; exit 1' diff --git a/test/--version.bats b/test/--version.bats index 6e372c5d..51f68802 100644 --- a/test/--version.bats +++ b/test/--version.bats @@ -2,9 +2,8 @@ load test_helper -export GIT_DIR="${PYENV_TEST_DIR}/.git" - -setup() { +_setup() { + export GIT_DIR="${PYENV_TEST_DIR}/.git" mkdir -p "$HOME" git config --global user.name "Tester" git config --global user.email "tester@test.local" diff --git a/test/init.bats b/test/init.bats index c0831d40..f5355591 100755 --- a/test/init.bats +++ b/test/init.bats @@ -2,7 +2,7 @@ load test_helper -setup() { +_setup() { export PATH="${PYENV_TEST_DIR}/bin:$PATH" } diff --git a/test/latest.bats b/test/latest.bats index 4acfa89f..a2c3778f 100644 --- a/test/latest.bats +++ b/test/latest.bats @@ -2,7 +2,7 @@ load test_helper -setup() { +_setup() { export PATH="${PYENV_TEST_DIR}/bin:$PATH" } diff --git a/test/local.bats b/test/local.bats index 9d97f144..98639673 100644 --- a/test/local.bats +++ b/test/local.bats @@ -2,7 +2,7 @@ load test_helper -setup() { +_setup() { mkdir -p "${PYENV_TEST_DIR}/myproject" cd "${PYENV_TEST_DIR}/myproject" } diff --git a/test/prefix.bats b/test/prefix.bats index 80271514..f52e520d 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -34,15 +34,15 @@ load test_helper } @test "prefix for system in /" { - mkdir -p "${BATS_TEST_DIRNAME}/libexec" - cat >"${BATS_TEST_DIRNAME}/libexec/pyenv-which" <"${PYENV_TEST_DIR}/libexec/pyenv-which" </dev/null || echo "$PYENV_TEST_DIR")" - mkdir -p "${PYENV_TEST_DIR}" - - if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then - export PYENV_TEST_DIR="$(realpath "$PYENV_TEST_DIR")" - else +setup() { + if ! enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then if [ -n "$PYENV_NATIVE_EXT" ]; then echo "pyenv: failed to load \`realpath' builtin" >&2 exit 1 fi fi + local bats_test_tmpdir="$(realpath "${BATS_TEST_TMPDIR}")" + if [ -z "${bats_test_tmpdir}" ];then + # Use readlink if running in a container instead of realpath lib + bats_test_tmpdir="$(readlink -f "${BATS_TEST_TMPDIR}")" + fi + + # update BATS_TEST_TMPDIR discover by realpath/readlink to avoid "//" + export BATS_TEST_TMPDIR="${bats_test_tmpdir}" + export PYENV_TEST_DIR="${BATS_TEST_TMPDIR}/pyenv" export PYENV_ROOT="${PYENV_TEST_DIR}/root" export HOME="${PYENV_TEST_DIR}/home" export PYENV_HOOK_PATH="${PYENV_ROOT}/pyenv.d" @@ -29,10 +31,11 @@ if [ -z "$PYENV_TEST_DIR" ]; then for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done unset xdg_var -fi -teardown() { - rm -rf "$PYENV_TEST_DIR" + # If test specific setup exist, run it + if [[ $(type -t _setup) == function ]];then + _setup + fi } flunk() { diff --git a/test/version-file-read.bats b/test/version-file-read.bats index acd9d781..6563eb6f 100644 --- a/test/version-file-read.bats +++ b/test/version-file-read.bats @@ -2,7 +2,7 @@ load test_helper -setup() { +_setup() { mkdir -p "${PYENV_TEST_DIR}/myproject" cd "${PYENV_TEST_DIR}/myproject" } diff --git a/test/version-file-write.bats b/test/version-file-write.bats index 1b62e977..ae6694f9 100644 --- a/test/version-file-write.bats +++ b/test/version-file-write.bats @@ -2,8 +2,8 @@ load test_helper -setup() { - mkdir -p "$PYENV_TEST_DIR" +_setup() { + mkdir -p "${PYENV_TEST_DIR}" cd "$PYENV_TEST_DIR" } diff --git a/test/version-file.bats b/test/version-file.bats index c46fb389..e2fb941c 100644 --- a/test/version-file.bats +++ b/test/version-file.bats @@ -2,8 +2,8 @@ load test_helper -setup() { - mkdir -p "$PYENV_TEST_DIR" +_setup() { + mkdir -p "${PYENV_TEST_DIR}" cd "$PYENV_TEST_DIR" } diff --git a/test/version-name.bats b/test/version-name.bats index 285794e4..cc179b97 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -6,8 +6,8 @@ create_version() { mkdir -p "${PYENV_ROOT}/versions/$1" } -setup() { - mkdir -p "$PYENV_TEST_DIR" +_setup() { + mkdir -p "${PYENV_TEST_DIR}" cd "$PYENV_TEST_DIR" } diff --git a/test/version-origin.bats b/test/version-origin.bats index cd7ec563..da0565fa 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -2,8 +2,8 @@ load test_helper -setup() { - mkdir -p "$PYENV_TEST_DIR" +_setup() { + mkdir -p "${PYENV_TEST_DIR}" cd "$PYENV_TEST_DIR" } diff --git a/test/version.bats b/test/version.bats index 78c6681b..a311b62f 100644 --- a/test/version.bats +++ b/test/version.bats @@ -6,8 +6,8 @@ create_version() { mkdir -p "${PYENV_ROOT}/versions/$1" } -setup() { - mkdir -p "$PYENV_TEST_DIR" +_setup() { + mkdir -p "${PYENV_ROOT}" cd "$PYENV_TEST_DIR" } @@ -78,4 +78,4 @@ OUT assert_output <