mirror of
https://github.com/sstephenson/bats.git
synced 2024-12-27 06:59:45 +01:00
43 lines
724 B
Bash
Executable File
43 lines
724 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
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"
|
|
}
|
|
|
|
expand_path() {
|
|
{ cd "$(dirname "$1")" 2>/dev/null
|
|
local dirname="$PWD"
|
|
cd "$OLDPWD"
|
|
echo "$dirname/$(basename "$1")"
|
|
} || echo "$1"
|
|
}
|
|
|
|
BATS_LIBEXEC="$(abs_dirname "$0")"
|
|
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
|
|
export PATH="$BATS_LIBEXEC:$PATH"
|
|
|
|
filename="$1"
|
|
if [ -z "$filename" ]; then
|
|
echo "usage: $0 <filename>" >&2
|
|
exit 1
|
|
else
|
|
shift
|
|
fi
|
|
|
|
exec bats-exec "$(expand_path "$filename")" "$@"
|