No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

140 líneas
3.2 KiB

  1. unset PYENV_VERSION
  2. unset PYENV_DIR
  3. # guard against executing this block twice due to bats internals
  4. if [ -z "$PYENV_TEST_DIR" ]; then
  5. PYENV_TEST_DIR="${BATS_TMPDIR}/pyenv"
  6. export PYENV_TEST_DIR="$(mktemp -d "${PYENV_TEST_DIR}.XXX" 2>/dev/null || echo "$PYENV_TEST_DIR")"
  7. if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
  8. export PYENV_TEST_DIR="$(realpath "$PYENV_TEST_DIR")"
  9. else
  10. if [ -n "$PYENV_NATIVE_EXT" ]; then
  11. echo "pyenv: failed to load \`realpath' builtin" >&2
  12. exit 1
  13. fi
  14. fi
  15. export PYENV_ROOT="${PYENV_TEST_DIR}/root"
  16. export HOME="${PYENV_TEST_DIR}/home"
  17. export PYENV_HOOK_PATH="${PYENV_ROOT}/pyenv.d"
  18. PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
  19. PATH="${PYENV_TEST_DIR}/bin:$PATH"
  20. PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH"
  21. PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
  22. PATH="${PYENV_ROOT}/shims:$PATH"
  23. export PATH
  24. for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done
  25. unset xdg_var
  26. fi
  27. teardown() {
  28. rm -rf "$PYENV_TEST_DIR"
  29. }
  30. flunk() {
  31. { if [ "$#" -eq 0 ]; then cat -
  32. else echo "$@"
  33. fi
  34. } | sed "s:${PYENV_TEST_DIR}:TEST_DIR:g" >&2
  35. return 1
  36. }
  37. assert_success() {
  38. if [ "$status" -ne 0 ]; then
  39. flunk "command failed with exit status $status"
  40. elif [ "$#" -gt 0 ]; then
  41. assert_output "$1"
  42. fi
  43. }
  44. assert_failure() {
  45. if [ "$status" -eq 0 ]; then
  46. flunk "expected failed exit status"
  47. elif [ "$#" -gt 0 ]; then
  48. assert_output "$1"
  49. fi
  50. }
  51. assert_equal() {
  52. if [ "$1" != "$2" ]; then
  53. { echo "expected: $1"
  54. echo "actual: $2"
  55. } | flunk
  56. fi
  57. }
  58. assert_output() {
  59. local expected
  60. if [ $# -eq 0 ]; then expected="$(cat -)"
  61. else expected="$1"
  62. fi
  63. assert_equal "$expected" "$output"
  64. }
  65. assert_line() {
  66. if [ "$1" -ge 0 ] 2>/dev/null; then
  67. assert_equal "$2" "${lines[$1]}"
  68. else
  69. local line
  70. for line in "${lines[@]}"; do
  71. if [ "$line" = "$1" ]; then return 0; fi
  72. done
  73. flunk "expected line \`$1'"
  74. fi
  75. }
  76. refute_line() {
  77. if [ "$1" -ge 0 ] 2>/dev/null; then
  78. local num_lines="${#lines[@]}"
  79. if [ "$1" -lt "$num_lines" ]; then
  80. flunk "output has $num_lines lines"
  81. fi
  82. else
  83. local line
  84. for line in "${lines[@]}"; do
  85. if [ "$line" = "$1" ]; then
  86. flunk "expected to not find line \`$line'"
  87. fi
  88. done
  89. fi
  90. }
  91. assert() {
  92. if ! "$@"; then
  93. flunk "failed: $@"
  94. fi
  95. }
  96. # Output a modified PATH that ensures that the given executable is not present,
  97. # but in which system utils necessary for pyenv operation are still available.
  98. path_without() {
  99. local exe="$1"
  100. local path=":${PATH}:"
  101. local found alt util
  102. for found in $(which -a "$exe"); do
  103. found="${found%/*}"
  104. if [ "$found" != "${PYENV_ROOT}/shims" ]; then
  105. alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
  106. mkdir -p "$alt"
  107. for util in bash head cut readlink greadlink; do
  108. if [ -x "${found}/$util" ]; then
  109. ln -s "${found}/$util" "${alt}/$util"
  110. fi
  111. done
  112. path="${path/:${found}:/:${alt}:}"
  113. fi
  114. done
  115. path="${path#:}"
  116. echo "${path%:}"
  117. }
  118. create_hook() {
  119. mkdir -p "${PYENV_HOOK_PATH}/$1"
  120. touch "${PYENV_HOOK_PATH}/$1/$2"
  121. if [ ! -t 0 ]; then
  122. cat > "${PYENV_HOOK_PATH}/$1/$2"
  123. fi
  124. }