mirror of
https://github.com/rbenv/rbenv.git
synced 2025-01-01 06:37:11 +01:00
Merge pull request #852 from jasonkarns/extract-hook-helper
Extract hook helper
This commit is contained in:
commit
c38833179b
8 changed files with 57 additions and 48 deletions
|
@ -43,27 +43,14 @@ ruby
|
|||
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" {
|
||||
hook_path="${RBENV_TEST_DIR}/rbenv.d"
|
||||
mkdir -p "${hook_path}/exec"
|
||||
cat > "${hook_path}/exec/hello.bash" <<SH
|
||||
create_hook exec hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
SH
|
||||
|
||||
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_line "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
|
|
@ -2,11 +2,6 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
create_hook() {
|
||||
mkdir -p "$1/$2"
|
||||
touch "$1/$2/$3"
|
||||
}
|
||||
|
||||
@test "prints usage help given no argument" {
|
||||
run rbenv-hooks
|
||||
assert_failure "Usage: rbenv hooks <command>"
|
||||
|
@ -15,11 +10,13 @@ create_hook() {
|
|||
@test "prints list of hooks" {
|
||||
path1="${RBENV_TEST_DIR}/rbenv.d"
|
||||
path2="${RBENV_TEST_DIR}/etc/rbenv_hooks"
|
||||
create_hook "$path1" exec "hello.bash"
|
||||
create_hook "$path1" exec "ahoy.bash"
|
||||
create_hook "$path1" exec "invalid.sh"
|
||||
create_hook "$path1" which "boom.bash"
|
||||
create_hook "$path2" exec "bueno.bash"
|
||||
RBENV_HOOK_PATH="$path1"
|
||||
create_hook exec "hello.bash"
|
||||
create_hook exec "ahoy.bash"
|
||||
create_hook exec "invalid.sh"
|
||||
create_hook which "boom.bash"
|
||||
RBENV_HOOK_PATH="$path2"
|
||||
create_hook exec "bueno.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||
assert_success
|
||||
|
@ -33,8 +30,10 @@ OUT
|
|||
@test "supports hook paths with spaces" {
|
||||
path1="${RBENV_TEST_DIR}/my hooks/rbenv.d"
|
||||
path2="${RBENV_TEST_DIR}/etc/rbenv hooks"
|
||||
create_hook "$path1" exec "hello.bash"
|
||||
create_hook "$path2" exec "ahoy.bash"
|
||||
RBENV_HOOK_PATH="$path1"
|
||||
create_hook exec "hello.bash"
|
||||
RBENV_HOOK_PATH="$path2"
|
||||
create_hook exec "ahoy.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||
assert_success
|
||||
|
@ -45,8 +44,8 @@ OUT
|
|||
}
|
||||
|
||||
@test "resolves relative paths" {
|
||||
path="${RBENV_TEST_DIR}/rbenv.d"
|
||||
create_hook "$path" exec "hello.bash"
|
||||
RBENV_HOOK_PATH="${RBENV_TEST_DIR}/rbenv.d"
|
||||
create_hook exec "hello.bash"
|
||||
mkdir -p "$HOME"
|
||||
|
||||
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" {
|
||||
unset 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"
|
||||
}
|
||||
|
|
|
@ -105,15 +105,13 @@ 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
|
||||
create_hook 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
|
||||
IFS=$' \t\n' run rbenv-rehash
|
||||
assert_success
|
||||
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 HOME="${RBENV_TEST_DIR}/home"
|
||||
export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d"
|
||||
|
||||
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
||||
PATH="${RBENV_TEST_DIR}/bin:$PATH"
|
||||
|
@ -129,3 +130,11 @@ path_without() {
|
|||
path="${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" {
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3"
|
||||
create_hook version-name test.bash <<<"RBENV_VERSION=1.9.3"
|
||||
|
||||
mkdir -p "${RBENV_ROOT}/rbenv.d/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
|
||||
RBENV_VERSION=1.8.7 run rbenv-version-name
|
||||
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" {
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3"
|
||||
|
|
|
@ -32,15 +32,24 @@ setup() {
|
|||
}
|
||||
|
||||
@test "reports from hook" {
|
||||
mkdir -p "${RBENV_ROOT}/rbenv.d/version-origin"
|
||||
cat > "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" <<HOOK
|
||||
RBENV_VERSION_ORIGIN=plugin
|
||||
HOOK
|
||||
create_hook version-origin test.bash <<<"RBENV_VERSION_ORIGIN=plugin"
|
||||
|
||||
RBENV_VERSION=1 RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" run rbenv-version-origin
|
||||
RBENV_VERSION=1 run rbenv-version-origin
|
||||
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" {
|
||||
RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
|
|
|
@ -101,15 +101,13 @@ OUT
|
|||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
hook_path="${RBENV_TEST_DIR}/rbenv.d"
|
||||
mkdir -p "${hook_path}/which"
|
||||
cat > "${hook_path}/which/hello.bash" <<SH
|
||||
create_hook which hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
exit
|
||||
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_output "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue