Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

74 строки
1.9 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. }
  20. @test "searches PATH for system version" {
  21. create_executable "${PYENV_TEST_DIR}/bin" "kill-all-humans"
  22. create_executable "${PYENV_ROOT}/shims" "kill-all-humans"
  23. PYENV_VERSION=system run pyenv-which kill-all-humans
  24. assert_success "${PYENV_TEST_DIR}/bin/kill-all-humans"
  25. }
  26. @test "version not installed" {
  27. create_executable "3.4" "py.test"
  28. PYENV_VERSION=3.3 run pyenv-which py.test
  29. assert_failure "pyenv: version \`3.3' is not installed"
  30. }
  31. @test "no executable found" {
  32. create_executable "2.7" "py.test"
  33. PYENV_VERSION=2.7 run pyenv-which fab
  34. assert_failure "pyenv: fab: command not found"
  35. }
  36. @test "executable found in other versions" {
  37. create_executable "2.7" "python"
  38. create_executable "3.3" "py.test"
  39. create_executable "3.4" "py.test"
  40. PYENV_VERSION=2.7 run pyenv-which py.test
  41. assert_failure
  42. assert_output <<OUT
  43. pyenv: py.test: command not found
  44. The \`py.test' command exists in these Python versions:
  45. 3.3
  46. 3.4
  47. OUT
  48. }
  49. @test "carries original IFS within hooks" {
  50. hook_path="${PYENV_TEST_DIR}/pyenv.d"
  51. mkdir -p "${hook_path}/which"
  52. cat > "${hook_path}/which/hello.bash" <<SH
  53. hellos=(\$(printf "hello\\tugly world\\nagain"))
  54. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  55. exit
  56. SH
  57. PYENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run pyenv-which anything
  58. assert_success
  59. assert_output "HELLO=:hello:ugly:world:again"
  60. }