Use create_hook helper

Use extracted create_hook helper in tests for:

- exec
- hooks
- rehash
- version-name
- version-origin
- which
This commit is contained in:
Jason Karns 2015-12-29 11:01:10 -05:00
parent 5ccba5d7cc
commit 0f7a2cad8d
6 changed files with 23 additions and 37 deletions

View file

@ -44,15 +44,13 @@ OUT
}
@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"
}

View file

@ -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

View file

@ -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"
}

View file

@ -25,13 +25,9 @@ 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"
}

View file

@ -32,12 +32,9 @@ 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"
}

View file

@ -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"
}