mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
add hook lookup tests
This commit is contained in:
parent
a7da06998e
commit
a81ace2ccb
2 changed files with 59 additions and 9 deletions
38
test/hooks.bats
Normal file
38
test/hooks.bats
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
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>"
|
||||
}
|
||||
|
||||
@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:$path2" run rbenv-hooks exec
|
||||
assert_success
|
||||
assert_line 0 "${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash"
|
||||
assert_line 1 "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash"
|
||||
assert_line 2 "${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash"
|
||||
}
|
||||
|
||||
@test "resolves relative paths" {
|
||||
path="${RBENV_TEST_DIR}/rbenv.d"
|
||||
create_hook "$path" exec "hello.bash"
|
||||
mkdir -p "$HOME"
|
||||
|
||||
RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec
|
||||
assert_success "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash"
|
||||
}
|
|
@ -15,7 +15,10 @@ teardown() {
|
|||
}
|
||||
|
||||
flunk() {
|
||||
echo "$@" | sed "s:${RBENV_ROOT}:\$RBENV_ROOT:" >&2
|
||||
{ if [ "$#" -eq 0 ]; then cat -
|
||||
else echo "$@"
|
||||
fi
|
||||
} | sed "s:${RBENV_TEST_DIR}:TEST_DIR:" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
|
@ -35,18 +38,27 @@ assert_failure() {
|
|||
fi
|
||||
}
|
||||
|
||||
assert_output() {
|
||||
if [ "$output" != "$1" ]; then
|
||||
flunk "expected: $1" || true
|
||||
flunk "got: $output"
|
||||
assert_equal() {
|
||||
if [ "$1" != "$2" ]; then
|
||||
{ echo "expected: $1"
|
||||
echo "actual: $2"
|
||||
} | flunk
|
||||
fi
|
||||
}
|
||||
|
||||
assert_output() {
|
||||
assert_equal "$1" "$output"
|
||||
}
|
||||
|
||||
assert_line() {
|
||||
if [ "$1" -ge 0 ] 2>/dev/null; then
|
||||
assert_equal "$2" "${lines[$1]}"
|
||||
else
|
||||
for line in "${lines[@]}"; do
|
||||
if [ "$line" = "$1" ]; then return 0; fi
|
||||
done
|
||||
flunk "expected line \`$1'"
|
||||
fi
|
||||
}
|
||||
|
||||
refute_line() {
|
||||
|
|
Loading…
Reference in a new issue