Merge pull request #852 from jasonkarns/extract-hook-helper
Extract hook helper
This commit is contained in:
commit
c38833179b
@ -43,27 +43,14 @@ ruby
|
|||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "supports hook path with spaces" {
|
|
||||||
hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks"
|
|
||||||
mkdir -p "${hook_path}/exec"
|
|
||||||
echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash"
|
|
||||||
|
|
||||||
export RBENV_VERSION=system
|
|
||||||
RBENV_HOOK_PATH="$hook_path" run rbenv-exec env
|
|
||||||
assert_success
|
|
||||||
assert_line "HELLO=from hook"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "carries original IFS within hooks" {
|
@test "carries original IFS within hooks" {
|
||||||
hook_path="${RBENV_TEST_DIR}/rbenv.d"
|
create_hook exec hello.bash <<SH
|
||||||
mkdir -p "${hook_path}/exec"
|
|
||||||
cat > "${hook_path}/exec/hello.bash" <<SH
|
|
||||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||||
SH
|
SH
|
||||||
|
|
||||||
export RBENV_VERSION=system
|
export RBENV_VERSION=system
|
||||||
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-exec env
|
IFS=$' \t\n' run rbenv-exec env
|
||||||
assert_success
|
assert_success
|
||||||
assert_line "HELLO=:hello:ugly:world:again"
|
assert_line "HELLO=:hello:ugly:world:again"
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,6 @@
|
|||||||
|
|
||||||
load test_helper
|
load test_helper
|
||||||
|
|
||||||
create_hook() {
|
|
||||||
mkdir -p "$1/$2"
|
|
||||||
touch "$1/$2/$3"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "prints usage help given no argument" {
|
@test "prints usage help given no argument" {
|
||||||
run rbenv-hooks
|
run rbenv-hooks
|
||||||
assert_failure "Usage: rbenv hooks <command>"
|
assert_failure "Usage: rbenv hooks <command>"
|
||||||
@ -15,11 +10,13 @@ create_hook() {
|
|||||||
@test "prints list of hooks" {
|
@test "prints list of hooks" {
|
||||||
path1="${RBENV_TEST_DIR}/rbenv.d"
|
path1="${RBENV_TEST_DIR}/rbenv.d"
|
||||||
path2="${RBENV_TEST_DIR}/etc/rbenv_hooks"
|
path2="${RBENV_TEST_DIR}/etc/rbenv_hooks"
|
||||||
create_hook "$path1" exec "hello.bash"
|
RBENV_HOOK_PATH="$path1"
|
||||||
create_hook "$path1" exec "ahoy.bash"
|
create_hook exec "hello.bash"
|
||||||
create_hook "$path1" exec "invalid.sh"
|
create_hook exec "ahoy.bash"
|
||||||
create_hook "$path1" which "boom.bash"
|
create_hook exec "invalid.sh"
|
||||||
create_hook "$path2" exec "bueno.bash"
|
create_hook which "boom.bash"
|
||||||
|
RBENV_HOOK_PATH="$path2"
|
||||||
|
create_hook exec "bueno.bash"
|
||||||
|
|
||||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||||
assert_success
|
assert_success
|
||||||
@ -33,8 +30,10 @@ OUT
|
|||||||
@test "supports hook paths with spaces" {
|
@test "supports hook paths with spaces" {
|
||||||
path1="${RBENV_TEST_DIR}/my hooks/rbenv.d"
|
path1="${RBENV_TEST_DIR}/my hooks/rbenv.d"
|
||||||
path2="${RBENV_TEST_DIR}/etc/rbenv hooks"
|
path2="${RBENV_TEST_DIR}/etc/rbenv hooks"
|
||||||
create_hook "$path1" exec "hello.bash"
|
RBENV_HOOK_PATH="$path1"
|
||||||
create_hook "$path2" exec "ahoy.bash"
|
create_hook exec "hello.bash"
|
||||||
|
RBENV_HOOK_PATH="$path2"
|
||||||
|
create_hook exec "ahoy.bash"
|
||||||
|
|
||||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||||
assert_success
|
assert_success
|
||||||
@ -45,8 +44,8 @@ OUT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "resolves relative paths" {
|
@test "resolves relative paths" {
|
||||||
path="${RBENV_TEST_DIR}/rbenv.d"
|
RBENV_HOOK_PATH="${RBENV_TEST_DIR}/rbenv.d"
|
||||||
create_hook "$path" exec "hello.bash"
|
create_hook exec "hello.bash"
|
||||||
mkdir -p "$HOME"
|
mkdir -p "$HOME"
|
||||||
|
|
||||||
RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec
|
RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec
|
||||||
|
@ -70,6 +70,7 @@ load test_helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "RBENV_HOOK_PATH includes rbenv built-in plugins" {
|
@test "RBENV_HOOK_PATH includes rbenv built-in plugins" {
|
||||||
|
unset RBENV_HOOK_PATH
|
||||||
run rbenv echo "RBENV_HOOK_PATH"
|
run rbenv echo "RBENV_HOOK_PATH"
|
||||||
assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
||||||
}
|
}
|
||||||
|
@ -105,15 +105,13 @@ OUT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "carries original IFS within hooks" {
|
@test "carries original IFS within hooks" {
|
||||||
hook_path="${RBENV_TEST_DIR}/rbenv.d"
|
create_hook rehash hello.bash <<SH
|
||||||
mkdir -p "${hook_path}/rehash"
|
|
||||||
cat > "${hook_path}/rehash/hello.bash" <<SH
|
|
||||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||||
exit
|
exit
|
||||||
SH
|
SH
|
||||||
|
|
||||||
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-rehash
|
IFS=$' \t\n' run rbenv-rehash
|
||||||
assert_success
|
assert_success
|
||||||
assert_output "HELLO=:hello:ugly:world:again"
|
assert_output "HELLO=:hello:ugly:world:again"
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ if [ -z "$RBENV_TEST_DIR" ]; then
|
|||||||
|
|
||||||
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
|
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
|
||||||
export HOME="${RBENV_TEST_DIR}/home"
|
export HOME="${RBENV_TEST_DIR}/home"
|
||||||
|
export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d"
|
||||||
|
|
||||||
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
||||||
PATH="${RBENV_TEST_DIR}/bin:$PATH"
|
PATH="${RBENV_TEST_DIR}/bin:$PATH"
|
||||||
@ -129,3 +130,11 @@ path_without() {
|
|||||||
path="${path#:}"
|
path="${path#:}"
|
||||||
echo "${path%:}"
|
echo "${path%:}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_hook() {
|
||||||
|
mkdir -p "${RBENV_HOOK_PATH}/$1"
|
||||||
|
touch "${RBENV_HOOK_PATH}/$1/$2"
|
||||||
|
if [ ! -t 0 ]; then
|
||||||
|
cat > "${RBENV_HOOK_PATH}/$1/$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
@ -25,16 +25,24 @@ setup() {
|
|||||||
@test "RBENV_VERSION can be overridden by hook" {
|
@test "RBENV_VERSION can be overridden by hook" {
|
||||||
create_version "1.8.7"
|
create_version "1.8.7"
|
||||||
create_version "1.9.3"
|
create_version "1.9.3"
|
||||||
|
create_hook version-name test.bash <<<"RBENV_VERSION=1.9.3"
|
||||||
|
|
||||||
mkdir -p "${RBENV_ROOT}/rbenv.d/version-name"
|
RBENV_VERSION=1.8.7 run rbenv-version-name
|
||||||
cat > "${RBENV_ROOT}/rbenv.d/version-name/test.bash" <<HOOK
|
|
||||||
RBENV_VERSION=1.9.3
|
|
||||||
HOOK
|
|
||||||
|
|
||||||
RBENV_VERSION=1.8.7 RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" run rbenv-version-name
|
|
||||||
assert_success "1.9.3"
|
assert_success "1.9.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "carries original IFS within hooks" {
|
||||||
|
create_hook version-name hello.bash <<SH
|
||||||
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||||
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||||
|
SH
|
||||||
|
|
||||||
|
export RBENV_VERSION=system
|
||||||
|
IFS=$' \t\n' run rbenv-version-name env
|
||||||
|
assert_success
|
||||||
|
assert_line "HELLO=:hello:ugly:world:again"
|
||||||
|
}
|
||||||
|
|
||||||
@test "RBENV_VERSION has precedence over local" {
|
@test "RBENV_VERSION has precedence over local" {
|
||||||
create_version "1.8.7"
|
create_version "1.8.7"
|
||||||
create_version "1.9.3"
|
create_version "1.9.3"
|
||||||
|
@ -32,15 +32,24 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "reports from hook" {
|
@test "reports from hook" {
|
||||||
mkdir -p "${RBENV_ROOT}/rbenv.d/version-origin"
|
create_hook version-origin test.bash <<<"RBENV_VERSION_ORIGIN=plugin"
|
||||||
cat > "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" <<HOOK
|
|
||||||
RBENV_VERSION_ORIGIN=plugin
|
|
||||||
HOOK
|
|
||||||
|
|
||||||
RBENV_VERSION=1 RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" run rbenv-version-origin
|
RBENV_VERSION=1 run rbenv-version-origin
|
||||||
assert_success "plugin"
|
assert_success "plugin"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "carries original IFS within hooks" {
|
||||||
|
create_hook version-origin hello.bash <<SH
|
||||||
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||||
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||||
|
SH
|
||||||
|
|
||||||
|
export RBENV_VERSION=system
|
||||||
|
IFS=$' \t\n' run rbenv-version-origin env
|
||||||
|
assert_success
|
||||||
|
assert_line "HELLO=:hello:ugly:world:again"
|
||||||
|
}
|
||||||
|
|
||||||
@test "doesn't inherit RBENV_VERSION_ORIGIN from environment" {
|
@test "doesn't inherit RBENV_VERSION_ORIGIN from environment" {
|
||||||
RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin
|
RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin
|
||||||
assert_success "${RBENV_ROOT}/version"
|
assert_success "${RBENV_ROOT}/version"
|
||||||
|
@ -101,15 +101,13 @@ OUT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "carries original IFS within hooks" {
|
@test "carries original IFS within hooks" {
|
||||||
hook_path="${RBENV_TEST_DIR}/rbenv.d"
|
create_hook which hello.bash <<SH
|
||||||
mkdir -p "${hook_path}/which"
|
|
||||||
cat > "${hook_path}/which/hello.bash" <<SH
|
|
||||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||||
exit
|
exit
|
||||||
SH
|
SH
|
||||||
|
|
||||||
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' RBENV_VERSION=system run rbenv-which anything
|
IFS=$' \t\n' RBENV_VERSION=system run rbenv-which anything
|
||||||
assert_success
|
assert_success
|
||||||
assert_output "HELLO=:hello:ugly:world:again"
|
assert_output "HELLO=:hello:ugly:world:again"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user