mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-14 20:39:55 -05:00
f1fdb9bbc8
It doesn't exist as a builtin, and it doesn't seem there is a way to detect support for a shell builtin that is portable. So, just detect fish and don't the rehash command at all. Fixes #478
114 lines
2.5 KiB
Bash
Executable file
114 lines
2.5 KiB
Bash
Executable file
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
|
|
create_executable() {
|
|
local bin="${RBENV_ROOT}/versions/${1}/bin"
|
|
mkdir -p "$bin"
|
|
touch "${bin}/$2"
|
|
chmod +x "${bin}/$2"
|
|
}
|
|
|
|
@test "empty rehash" {
|
|
assert [ ! -d "${RBENV_ROOT}/shims" ]
|
|
run rbenv-rehash
|
|
assert_success ""
|
|
assert [ -d "${RBENV_ROOT}/shims" ]
|
|
rmdir "${RBENV_ROOT}/shims"
|
|
}
|
|
|
|
@test "non-writable shims directory" {
|
|
mkdir -p "${RBENV_ROOT}/shims"
|
|
chmod -w "${RBENV_ROOT}/shims"
|
|
run rbenv-rehash
|
|
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable"
|
|
}
|
|
|
|
@test "rehash in progress" {
|
|
mkdir -p "${RBENV_ROOT}/shims"
|
|
touch "${RBENV_ROOT}/shims/.rbenv-shim"
|
|
run rbenv-rehash
|
|
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"
|
|
assert_success
|
|
assert_output <<OUT
|
|
rake
|
|
rspec
|
|
ruby
|
|
OUT
|
|
}
|
|
|
|
@test "removes stale shims" {
|
|
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" ]
|
|
}
|
|
|
|
@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
|
|
}
|
|
|
|
@test "carries original IFS within hooks" {
|
|
hook_path="${RBENV_TEST_DIR}/rbenv.d"
|
|
mkdir -p "${hook_path}/rehash"
|
|
cat > "${hook_path}/rehash/hello.bash" <<SH
|
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
|
exit
|
|
SH
|
|
|
|
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-rehash
|
|
assert_success
|
|
assert_output "HELLO=:hello:ugly:world:again"
|
|
}
|
|
|
|
@test "sh-rehash in bash" {
|
|
create_executable "2.0" "ruby"
|
|
RBENV_SHELL=bash run rbenv-sh-rehash
|
|
assert_success "hash -r 2>/dev/null || true"
|
|
assert [ -x "${RBENV_ROOT}/shims/ruby" ]
|
|
}
|
|
|
|
@test "sh-rehash in fish" {
|
|
create_executable "2.0" "ruby"
|
|
RBENV_SHELL=fish run rbenv-sh-rehash
|
|
assert_success ""
|
|
assert [ -x "${RBENV_ROOT}/shims/ruby" ]
|
|
}
|