選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

139 行
4.2 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 "doesn't include current directory in PATH search" {
  48. export PATH="$(path_without "kill-all-humans")"
  49. mkdir -p "$PYENV_TEST_DIR"
  50. cd "$PYENV_TEST_DIR"
  51. touch kill-all-humans
  52. chmod +x kill-all-humans
  53. PYENV_VERSION=system run pyenv-which kill-all-humans
  54. assert_failure "pyenv: kill-all-humans: command not found"
  55. }
  56. @test "version not installed" {
  57. create_executable "3.4" "py.test"
  58. PYENV_VERSION=3.3 run pyenv-which py.test
  59. assert_failure "pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)"
  60. }
  61. @test "versions not installed" {
  62. create_executable "3.4" "py.test"
  63. PYENV_VERSION=2.7:3.3 run pyenv-which py.test
  64. assert_failure <<OUT
  65. pyenv: version \`2.7' is not installed (set by PYENV_VERSION environment variable)
  66. pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)
  67. OUT
  68. }
  69. @test "no executable found" {
  70. create_executable "2.7" "py.test"
  71. PYENV_VERSION=2.7 run pyenv-which fab
  72. assert_failure "pyenv: fab: command not found"
  73. }
  74. @test "no executable found for system version" {
  75. export PATH="$(path_without "py.test")"
  76. PYENV_VERSION=system run pyenv-which py.test
  77. assert_failure "pyenv: py.test: command not found"
  78. }
  79. @test "executable found in other versions" {
  80. create_executable "2.7" "python"
  81. create_executable "3.3" "py.test"
  82. create_executable "3.4" "py.test"
  83. PYENV_VERSION=2.7 run pyenv-which py.test
  84. assert_failure
  85. assert_output <<OUT
  86. pyenv: py.test: command not found
  87. The \`py.test' command exists in these Python versions:
  88. 3.3
  89. 3.4
  90. OUT
  91. }
  92. @test "carries original IFS within hooks" {
  93. hook_path="${PYENV_TEST_DIR}/pyenv.d"
  94. mkdir -p "${hook_path}/which"
  95. cat > "${hook_path}/which/hello.bash" <<SH
  96. hellos=(\$(printf "hello\\tugly world\\nagain"))
  97. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  98. exit
  99. SH
  100. PYENV_HOOK_PATH="$hook_path" IFS=$' \t\n' PYENV_VERSION=system run pyenv-which anything
  101. assert_success
  102. assert_output "HELLO=:hello:ugly:world:again"
  103. }
  104. @test "discovers version from pyenv-version-name" {
  105. mkdir -p "$PYENV_ROOT"
  106. cat > "${PYENV_ROOT}/version" <<<"3.4"
  107. create_executable "3.4" "python"
  108. mkdir -p "$PYENV_TEST_DIR"
  109. cd "$PYENV_TEST_DIR"
  110. PYENV_VERSION= run pyenv-which python
  111. assert_success "${PYENV_ROOT}/versions/3.4/bin/python"
  112. }