You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 regels
2.7 KiB

10 jaren geleden
  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_executable() {
  4. local bin="${PYENV_ROOT}/versions/${1}/bin"
  5. mkdir -p "$bin"
  6. touch "${bin}/$2"
  7. chmod +x "${bin}/$2"
  8. }
  9. @test "empty rehash" {
  10. assert [ ! -d "${PYENV_ROOT}/shims" ]
  11. run pyenv-rehash
  12. assert_success ""
  13. assert [ -d "${PYENV_ROOT}/shims" ]
  14. rmdir "${PYENV_ROOT}/shims"
  15. }
  16. @test "non-writable shims directory" {
  17. mkdir -p "${PYENV_ROOT}/shims"
  18. chmod -w "${PYENV_ROOT}/shims"
  19. run pyenv-rehash
  20. assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims isn't writable"
  21. }
  22. @test "rehash in progress" {
  23. export PYENV_REHASH_TIMEOUT=1
  24. mkdir -p "${PYENV_ROOT}/shims"
  25. touch "${PYENV_ROOT}/shims/.pyenv-shim"
  26. run pyenv-rehash
  27. assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims/.pyenv-shim exists"
  28. }
  29. @test "wait until lock acquisition" {
  30. export PYENV_REHASH_TIMEOUT=5
  31. mkdir -p "${PYENV_ROOT}/shims"
  32. touch "${PYENV_ROOT}/shims/.pyenv-shim"
  33. bash -c "sleep 1 && rm -f ${PYENV_ROOT}/shims/.pyenv-shim" &
  34. run pyenv-rehash
  35. assert_success
  36. }
  37. @test "creates shims" {
  38. create_executable "2.7" "python"
  39. create_executable "2.7" "fab"
  40. create_executable "3.4" "python"
  41. create_executable "3.4" "py.test"
  42. assert [ ! -e "${PYENV_ROOT}/shims/fab" ]
  43. assert [ ! -e "${PYENV_ROOT}/shims/python" ]
  44. assert [ ! -e "${PYENV_ROOT}/shims/py.test" ]
  45. run pyenv-rehash
  46. assert_success ""
  47. run ls "${PYENV_ROOT}/shims"
  48. assert_success
  49. assert_output <<OUT
  50. fab
  51. py.test
  52. python
  53. OUT
  54. }
  55. @test "removes stale shims" {
  56. mkdir -p "${PYENV_ROOT}/shims"
  57. touch "${PYENV_ROOT}/shims/oldshim1"
  58. chmod +x "${PYENV_ROOT}/shims/oldshim1"
  59. create_executable "3.4" "fab"
  60. create_executable "3.4" "python"
  61. run pyenv-rehash
  62. assert_success ""
  63. assert [ ! -e "${PYENV_ROOT}/shims/oldshim1" ]
  64. }
  65. @test "binary install locations containing spaces" {
  66. create_executable "dirname1 p247" "python"
  67. create_executable "dirname2 preview1" "py.test"
  68. assert [ ! -e "${PYENV_ROOT}/shims/python" ]
  69. assert [ ! -e "${PYENV_ROOT}/shims/py.test" ]
  70. run pyenv-rehash
  71. assert_success ""
  72. run ls "${PYENV_ROOT}/shims"
  73. assert_success
  74. assert_output <<OUT
  75. py.test
  76. python
  77. OUT
  78. }
  79. @test "carries original IFS within hooks" {
  80. create_hook rehash hello.bash <<SH
  81. hellos=(\$(printf "hello\\tugly world\\nagain"))
  82. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  83. exit
  84. SH
  85. IFS=$' \t\n' run pyenv-rehash
  86. assert_success
  87. assert_output "HELLO=:hello:ugly:world:again"
  88. }
  89. @test "sh-rehash in bash" {
  90. create_executable "3.4" "python"
  91. PYENV_SHELL=bash run pyenv-sh-rehash
  92. assert_success "hash -r 2>/dev/null || true"
  93. assert [ -x "${PYENV_ROOT}/shims/python" ]
  94. }
  95. @test "sh-rehash in fish" {
  96. create_executable "3.4" "python"
  97. PYENV_SHELL=fish run pyenv-sh-rehash
  98. assert_success ""
  99. assert [ -x "${PYENV_ROOT}/shims/python" ]
  100. }