2013-03-07 00:13:50 -05:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
2013-03-07 15:05:49 -05:00
|
|
|
load test_helper
|
2013-03-07 00:13:50 -05:00
|
|
|
|
2013-04-06 06:30:21 -04:00
|
|
|
create_executable() {
|
2022-09-25 20:57:15 -04:00
|
|
|
local exe="${RBENV_ROOT}/versions/${1}/bin/${2}"
|
|
|
|
[ -n "$2" ] || exe="$1"
|
|
|
|
mkdir -p "${exe%/*}"
|
|
|
|
touch "$exe"
|
|
|
|
chmod +x "$exe"
|
2013-04-06 06:30:21 -04:00
|
|
|
}
|
|
|
|
|
2013-03-07 00:13:50 -05:00
|
|
|
@test "empty rehash" {
|
2013-03-07 15:05:49 -05:00
|
|
|
assert [ ! -d "${RBENV_ROOT}/shims" ]
|
2013-03-07 00:13:50 -05:00
|
|
|
run rbenv-rehash
|
2013-04-06 06:30:21 -04:00
|
|
|
assert_success ""
|
2013-03-07 15:05:49 -05:00
|
|
|
assert [ -d "${RBENV_ROOT}/shims" ]
|
|
|
|
rmdir "${RBENV_ROOT}/shims"
|
2013-03-07 00:13:50 -05:00
|
|
|
}
|
|
|
|
|
2013-03-07 15:05:49 -05:00
|
|
|
@test "non-writable shims directory" {
|
|
|
|
mkdir -p "${RBENV_ROOT}/shims"
|
|
|
|
chmod -w "${RBENV_ROOT}/shims"
|
2013-03-07 00:13:50 -05:00
|
|
|
run rbenv-rehash
|
2013-04-06 06:30:21 -04:00
|
|
|
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable"
|
2013-03-07 00:13:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "rehash in progress" {
|
2013-03-07 15:05:49 -05:00
|
|
|
mkdir -p "${RBENV_ROOT}/shims"
|
|
|
|
touch "${RBENV_ROOT}/shims/.rbenv-shim"
|
2013-03-07 00:13:50 -05:00
|
|
|
run rbenv-rehash
|
2013-04-06 06:30:21 -04:00
|
|
|
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "creates shims" {
|
|
|
|
create_executable "1.8" "ruby"
|
|
|
|
create_executable "1.8" "rake"
|
|
|
|
create_executable "2.0" "ruby"
|
|
|
|
create_executable "2.0" "rspec"
|
|
|
|
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/ruby" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/rake" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/rspec" ]
|
|
|
|
|
|
|
|
run rbenv-rehash
|
|
|
|
assert_success ""
|
|
|
|
|
|
|
|
run ls "${RBENV_ROOT}/shims"
|
2013-04-06 08:10:44 -04:00
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
|
|
|
rake
|
|
|
|
rspec
|
|
|
|
ruby
|
|
|
|
OUT
|
2013-03-07 00:13:50 -05:00
|
|
|
}
|
2013-04-16 08:01:04 -04:00
|
|
|
|
2014-10-14 23:12:28 -04:00
|
|
|
@test "removes outdated shims" {
|
2013-09-23 02:16:15 -04:00
|
|
|
mkdir -p "${RBENV_ROOT}/shims"
|
|
|
|
touch "${RBENV_ROOT}/shims/oldshim1"
|
|
|
|
chmod +x "${RBENV_ROOT}/shims/oldshim1"
|
|
|
|
|
|
|
|
create_executable "2.0" "rake"
|
|
|
|
create_executable "2.0" "ruby"
|
|
|
|
|
|
|
|
run rbenv-rehash
|
|
|
|
assert_success ""
|
|
|
|
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/oldshim1" ]
|
|
|
|
}
|
|
|
|
|
2014-10-14 23:12:28 -04:00
|
|
|
@test "do exact matches when removing stale shims" {
|
|
|
|
create_executable "2.0" "unicorn_rails"
|
|
|
|
create_executable "2.0" "rspec-core"
|
|
|
|
|
|
|
|
rbenv-rehash
|
|
|
|
|
|
|
|
cp "$RBENV_ROOT"/shims/{rspec-core,rspec}
|
|
|
|
cp "$RBENV_ROOT"/shims/{rspec-core,rails}
|
|
|
|
cp "$RBENV_ROOT"/shims/{rspec-core,uni}
|
|
|
|
chmod +x "$RBENV_ROOT"/shims/{rspec,rails,uni}
|
|
|
|
|
|
|
|
run rbenv-rehash
|
|
|
|
assert_success ""
|
|
|
|
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/rails" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/rake" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/uni" ]
|
|
|
|
}
|
|
|
|
|
2013-09-23 02:16:15 -04:00
|
|
|
@test "binary install locations containing spaces" {
|
|
|
|
create_executable "dirname1 p247" "ruby"
|
|
|
|
create_executable "dirname2 preview1" "rspec"
|
|
|
|
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/ruby" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/rspec" ]
|
|
|
|
|
|
|
|
run rbenv-rehash
|
|
|
|
assert_success ""
|
|
|
|
|
|
|
|
run ls "${RBENV_ROOT}/shims"
|
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
|
|
|
rspec
|
|
|
|
ruby
|
|
|
|
OUT
|
|
|
|
}
|
|
|
|
|
2022-10-07 06:56:54 -04:00
|
|
|
@test "no shims for user-installed gems" {
|
|
|
|
create_executable "2.7.5" "ruby"
|
|
|
|
create_executable "3.1.2" "ruby"
|
|
|
|
create_executable "${HOME}/.gem/ruby/2.7.0/bin/lolcat"
|
2022-09-25 20:57:15 -04:00
|
|
|
create_executable "${HOME}/.gem/ruby/3.1.0/bin/pinecone"
|
|
|
|
|
|
|
|
run rbenv-rehash
|
|
|
|
assert_success ""
|
|
|
|
|
2022-10-07 06:56:54 -04:00
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/lolcat" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/pinecone" ]
|
2022-09-25 20:57:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "explicit gem home" {
|
|
|
|
create_executable "${HOME}/mygems/bin/lolcat"
|
|
|
|
create_executable "${HOME}/mygems/bin/pinecone"
|
|
|
|
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/lolcat" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/pinecone" ]
|
|
|
|
|
|
|
|
GEM_HOME="${HOME}/mygems" run rbenv-rehash
|
|
|
|
assert_success ""
|
|
|
|
|
|
|
|
run ls "${RBENV_ROOT}/shims"
|
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
|
|
|
lolcat
|
|
|
|
pinecone
|
|
|
|
OUT
|
|
|
|
}
|
|
|
|
|
2013-04-16 08:01:04 -04:00
|
|
|
@test "carries original IFS within hooks" {
|
2015-12-29 11:01:10 -05:00
|
|
|
create_hook rehash hello.bash <<SH
|
2013-04-16 08:01:04 -04:00
|
|
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
|
|
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
|
|
|
exit
|
|
|
|
SH
|
|
|
|
|
2015-12-29 11:01:10 -05:00
|
|
|
IFS=$' \t\n' run rbenv-rehash
|
2013-04-16 08:01:04 -04:00
|
|
|
assert_success
|
|
|
|
assert_output "HELLO=:hello:ugly:world:again"
|
|
|
|
}
|
2013-09-28 09:04:24 -04:00
|
|
|
|
|
|
|
@test "sh-rehash in bash" {
|
|
|
|
create_executable "2.0" "ruby"
|
2013-09-28 12:43:39 -04:00
|
|
|
RBENV_SHELL=bash run rbenv-sh-rehash
|
2013-09-28 09:04:24 -04:00
|
|
|
assert_success "hash -r 2>/dev/null || true"
|
|
|
|
assert [ -x "${RBENV_ROOT}/shims/ruby" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "sh-rehash in fish" {
|
|
|
|
create_executable "2.0" "ruby"
|
2013-09-28 12:43:39 -04:00
|
|
|
RBENV_SHELL=fish run rbenv-sh-rehash
|
2013-10-31 14:16:26 -04:00
|
|
|
assert_success ""
|
2013-09-28 09:04:24 -04:00
|
|
|
assert [ -x "${RBENV_ROOT}/shims/ruby" ]
|
|
|
|
}
|