Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

112 lignes
2.5 KiB

il y a 10 ans
  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. mkdir -p "${PYENV_ROOT}/shims"
  24. touch "${PYENV_ROOT}/shims/.pyenv-shim"
  25. run pyenv-rehash
  26. assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims/.pyenv-shim exists"
  27. }
  28. @test "creates shims" {
  29. create_executable "2.7" "python"
  30. create_executable "2.7" "fab"
  31. create_executable "3.4" "python"
  32. create_executable "3.4" "py.test"
  33. assert [ ! -e "${PYENV_ROOT}/shims/fab" ]
  34. assert [ ! -e "${PYENV_ROOT}/shims/python" ]
  35. assert [ ! -e "${PYENV_ROOT}/shims/py.test" ]
  36. run pyenv-rehash
  37. assert_success ""
  38. run ls "${PYENV_ROOT}/shims"
  39. assert_success
  40. assert_output <<OUT
  41. fab
  42. py.test
  43. python
  44. OUT
  45. }
  46. @test "removes stale shims" {
  47. mkdir -p "${PYENV_ROOT}/shims"
  48. touch "${PYENV_ROOT}/shims/oldshim1"
  49. chmod +x "${PYENV_ROOT}/shims/oldshim1"
  50. create_executable "3.4" "fab"
  51. create_executable "3.4" "python"
  52. run pyenv-rehash
  53. assert_success ""
  54. assert [ ! -e "${PYENV_ROOT}/shims/oldshim1" ]
  55. }
  56. @test "binary install locations containing spaces" {
  57. create_executable "dirname1 p247" "python"
  58. create_executable "dirname2 preview1" "py.test"
  59. assert [ ! -e "${PYENV_ROOT}/shims/python" ]
  60. assert [ ! -e "${PYENV_ROOT}/shims/py.test" ]
  61. run pyenv-rehash
  62. assert_success ""
  63. run ls "${PYENV_ROOT}/shims"
  64. assert_success
  65. assert_output <<OUT
  66. py.test
  67. python
  68. OUT
  69. }
  70. @test "carries original IFS within hooks" {
  71. create_hook rehash hello.bash <<SH
  72. hellos=(\$(printf "hello\\tugly world\\nagain"))
  73. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  74. exit
  75. SH
  76. IFS=$' \t\n' run pyenv-rehash
  77. assert_success
  78. assert_output "HELLO=:hello:ugly:world:again"
  79. }
  80. @test "sh-rehash in bash" {
  81. create_executable "3.4" "python"
  82. PYENV_SHELL=bash run pyenv-sh-rehash
  83. assert_success "hash -r 2>/dev/null || true"
  84. assert [ -x "${PYENV_ROOT}/shims/python" ]
  85. }
  86. @test "sh-rehash in fish" {
  87. create_executable "3.4" "python"
  88. PYENV_SHELL=fish run pyenv-sh-rehash
  89. assert_success ""
  90. assert [ -x "${PYENV_ROOT}/shims/python" ]
  91. }