25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.5 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_executable() {
  4. local bin
  5. if [[ $1 == */* ]]; then bin="$1"
  6. else bin="${PYENV_ROOT}/versions/${1}/bin"
  7. fi
  8. mkdir -p "$bin"
  9. touch "${bin}/$2"
  10. chmod +x "${bin}/$2"
  11. }
  12. @test "outputs path to executable" {
  13. create_executable "2.7" "python"
  14. create_executable "3.4" "py.test"
  15. PYENV_VERSION=2.7 run pyenv-which python
  16. assert_success "${PYENV_ROOT}/versions/2.7/bin/python"
  17. PYENV_VERSION=3.4 run pyenv-which py.test
  18. assert_success "${PYENV_ROOT}/versions/3.4/bin/py.test"
  19. PYENV_VERSION=3.4:2.7 run pyenv-which py.test
  20. assert_success "${PYENV_ROOT}/versions/3.4/bin/py.test"
  21. }
  22. @test "searches PATH for system version" {
  23. create_executable "${PYENV_TEST_DIR}/bin" "kill-all-humans"
  24. create_executable "${PYENV_ROOT}/shims" "kill-all-humans"
  25. PYENV_VERSION=system run pyenv-which kill-all-humans
  26. assert_success "${PYENV_TEST_DIR}/bin/kill-all-humans"
  27. }
  28. @test "searches PATH for system version (shims prepended)" {
  29. create_executable "${PYENV_TEST_DIR}/bin" "kill-all-humans"
  30. create_executable "${PYENV_ROOT}/shims" "kill-all-humans"
  31. PATH="${PYENV_ROOT}/shims:$PATH" PYENV_VERSION=system run pyenv-which kill-all-humans
  32. assert_success "${PYENV_TEST_DIR}/bin/kill-all-humans"
  33. }
  34. @test "searches PATH for system version (shims appended)" {
  35. create_executable "${PYENV_TEST_DIR}/bin" "kill-all-humans"
  36. create_executable "${PYENV_ROOT}/shims" "kill-all-humans"
  37. PATH="$PATH:${PYENV_ROOT}/shims" PYENV_VERSION=system run pyenv-which kill-all-humans
  38. assert_success "${PYENV_TEST_DIR}/bin/kill-all-humans"
  39. }
  40. @test "searches PATH for system version (shims spread)" {
  41. create_executable "${PYENV_TEST_DIR}/bin" "kill-all-humans"
  42. create_executable "${PYENV_ROOT}/shims" "kill-all-humans"
  43. PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/shims:/tmp/non-existent:$PATH:${PYENV_ROOT}/shims" \
  44. PYENV_VERSION=system run pyenv-which kill-all-humans
  45. assert_success "${PYENV_TEST_DIR}/bin/kill-all-humans"
  46. }
  47. @test "version not installed" {
  48. create_executable "3.4" "py.test"
  49. PYENV_VERSION=3.3 run pyenv-which py.test
  50. assert_failure "pyenv: version \`3.3' is not installed"
  51. }
  52. @test "versions not installed" {
  53. create_executable "3.4" "py.test"
  54. PYENV_VERSION=2.7:3.3 run pyenv-which py.test
  55. assert_failure <<OUT
  56. pyenv: version \`2.7' is not installed
  57. pyenv: version \`3.3' is not installed
  58. OUT
  59. }
  60. @test "no executable found" {
  61. create_executable "2.7" "py.test"
  62. PYENV_VERSION=2.7 run pyenv-which fab
  63. assert_failure "pyenv: fab: command not found"
  64. }
  65. @test "executable found in other versions" {
  66. create_executable "2.7" "python"
  67. create_executable "3.3" "py.test"
  68. create_executable "3.4" "py.test"
  69. PYENV_VERSION=2.7 run pyenv-which py.test
  70. assert_failure
  71. assert_output <<OUT
  72. pyenv: py.test: command not found
  73. The \`py.test' command exists in these Python versions:
  74. 3.3
  75. 3.4
  76. OUT
  77. }
  78. @test "carries original IFS within hooks" {
  79. hook_path="${PYENV_TEST_DIR}/pyenv.d"
  80. mkdir -p "${hook_path}/which"
  81. cat > "${hook_path}/which/hello.bash" <<SH
  82. hellos=(\$(printf "hello\\tugly world\\nagain"))
  83. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  84. exit
  85. SH
  86. PYENV_HOOK_PATH="$hook_path" IFS=$' \t\n' PYENV_VERSION=system run pyenv-which anything
  87. assert_success
  88. assert_output "HELLO=:hello:ugly:world:again"
  89. }
  90. @test "discovers version from pyenv-version-name" {
  91. mkdir -p "$PYENV_ROOT"
  92. cat > "${PYENV_ROOT}/version" <<<"3.4"
  93. create_executable "3.4" "python"
  94. mkdir -p "$PYENV_TEST_DIR"
  95. cd "$PYENV_TEST_DIR"
  96. PYENV_VERSION= run pyenv-which python
  97. assert_success "${PYENV_ROOT}/versions/3.4/bin/python"
  98. }