diff --git a/test/test-helper.sh b/test/test-helper.sh index f435b12..912fa58 100644 --- a/test/test-helper.sh +++ b/test/test-helper.sh @@ -1,12 +1,39 @@ +[ -n "$TEST_DEBUG" ] && set -x + +resolve_link() { + $(type -p greadlink readlink | head -1) $1 +} + +abs_dirname() { + local cwd="$(pwd)" + local path="$1" + + while [ -n "$path" ]; do + cd "${path%/*}" + local name="${path##*/}" + path="$(resolve_link "$name" || true)" + done + + pwd + cd "$cwd" +} + # Set testroot variable. -testroot="$(dirname "$BASH_SOURCE")" +testroot="$(abs_dirname "$BASH_SOURCE")" + +# Set root variable. +root="$(abs_dirname "$testroot/../..")" + +# Setup PATH environment variable. +PATH="$root/bin:$root/libexec:$PATH" # Include assert.sh testing library. -source "$testroot/assert.sh" -source "$testroot/stub.sh" +source "${testroot}/assert.sh" +source "${testroot}/stub.sh" + # -# Additional test helpers. +# Test Helpers # # Silent shortcut to "cd -".