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.

131 lines
2.9 KiB

преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_executable() {
  4. local bin="${RBENV_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 "${RBENV_ROOT}/shims" ]
  11. run rbenv-rehash
  12. assert_success ""
  13. assert [ -d "${RBENV_ROOT}/shims" ]
  14. rmdir "${RBENV_ROOT}/shims"
  15. }
  16. @test "non-writable shims directory" {
  17. mkdir -p "${RBENV_ROOT}/shims"
  18. chmod -w "${RBENV_ROOT}/shims"
  19. run rbenv-rehash
  20. assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable"
  21. }
  22. @test "rehash in progress" {
  23. mkdir -p "${RBENV_ROOT}/shims"
  24. touch "${RBENV_ROOT}/shims/.rbenv-shim"
  25. run rbenv-rehash
  26. assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists"
  27. }
  28. @test "creates shims" {
  29. create_executable "1.8" "ruby"
  30. create_executable "1.8" "rake"
  31. create_executable "2.0" "ruby"
  32. create_executable "2.0" "rspec"
  33. assert [ ! -e "${RBENV_ROOT}/shims/ruby" ]
  34. assert [ ! -e "${RBENV_ROOT}/shims/rake" ]
  35. assert [ ! -e "${RBENV_ROOT}/shims/rspec" ]
  36. run rbenv-rehash
  37. assert_success ""
  38. run ls "${RBENV_ROOT}/shims"
  39. assert_success
  40. assert_output <<OUT
  41. rake
  42. rspec
  43. ruby
  44. OUT
  45. }
  46. @test "removes outdated shims" {
  47. mkdir -p "${RBENV_ROOT}/shims"
  48. touch "${RBENV_ROOT}/shims/oldshim1"
  49. chmod +x "${RBENV_ROOT}/shims/oldshim1"
  50. create_executable "2.0" "rake"
  51. create_executable "2.0" "ruby"
  52. run rbenv-rehash
  53. assert_success ""
  54. assert [ ! -e "${RBENV_ROOT}/shims/oldshim1" ]
  55. }
  56. @test "do exact matches when removing stale shims" {
  57. create_executable "2.0" "unicorn_rails"
  58. create_executable "2.0" "rspec-core"
  59. rbenv-rehash
  60. cp "$RBENV_ROOT"/shims/{rspec-core,rspec}
  61. cp "$RBENV_ROOT"/shims/{rspec-core,rails}
  62. cp "$RBENV_ROOT"/shims/{rspec-core,uni}
  63. chmod +x "$RBENV_ROOT"/shims/{rspec,rails,uni}
  64. run rbenv-rehash
  65. assert_success ""
  66. assert [ ! -e "${RBENV_ROOT}/shims/rails" ]
  67. assert [ ! -e "${RBENV_ROOT}/shims/rake" ]
  68. assert [ ! -e "${RBENV_ROOT}/shims/uni" ]
  69. }
  70. @test "binary install locations containing spaces" {
  71. create_executable "dirname1 p247" "ruby"
  72. create_executable "dirname2 preview1" "rspec"
  73. assert [ ! -e "${RBENV_ROOT}/shims/ruby" ]
  74. assert [ ! -e "${RBENV_ROOT}/shims/rspec" ]
  75. run rbenv-rehash
  76. assert_success ""
  77. run ls "${RBENV_ROOT}/shims"
  78. assert_success
  79. assert_output <<OUT
  80. rspec
  81. ruby
  82. OUT
  83. }
  84. @test "carries original IFS within hooks" {
  85. create_hook rehash hello.bash <<SH
  86. hellos=(\$(printf "hello\\tugly world\\nagain"))
  87. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  88. exit
  89. SH
  90. IFS=$' \t\n' run rbenv-rehash
  91. assert_success
  92. assert_output "HELLO=:hello:ugly:world:again"
  93. }
  94. @test "sh-rehash in bash" {
  95. create_executable "2.0" "ruby"
  96. RBENV_SHELL=bash run rbenv-sh-rehash
  97. assert_success "hash -r 2>/dev/null || true"
  98. assert [ -x "${RBENV_ROOT}/shims/ruby" ]
  99. }
  100. @test "sh-rehash in fish" {
  101. create_executable "2.0" "ruby"
  102. RBENV_SHELL=fish run rbenv-sh-rehash
  103. assert_success ""
  104. assert [ -x "${RBENV_ROOT}/shims/ruby" ]
  105. }