2011-12-28 19:40:14 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2011-12-30 21:12:15 +01:00
|
|
|
version() {
|
|
|
|
echo "Bats 0.1.0"
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:40:14 +01:00
|
|
|
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() {
|
2011-12-28 23:21:48 +01:00
|
|
|
{ cd "$(dirname "$1")" 2>/dev/null
|
|
|
|
local dirname="$PWD"
|
|
|
|
cd "$OLDPWD"
|
|
|
|
echo "$dirname/$(basename "$1")"
|
|
|
|
} || echo "$1"
|
2011-12-28 19:40:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BATS_LIBEXEC="$(abs_dirname "$0")"
|
|
|
|
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
|
|
|
|
export PATH="$BATS_LIBEXEC:$PATH"
|
|
|
|
|
2011-12-30 21:12:15 +01:00
|
|
|
if [ "$1" = "-v" ] || [ "$1" = "--version" ]; then
|
|
|
|
version
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-04-09 06:25:19 +02:00
|
|
|
count_only=""
|
|
|
|
if [ "$1" = "-c" ]; then
|
|
|
|
count_only="-c"
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2011-12-28 19:40:14 +01:00
|
|
|
filename="$1"
|
|
|
|
if [ -z "$filename" ]; then
|
2011-12-30 21:12:15 +01:00
|
|
|
{ version
|
2012-04-09 06:25:19 +02:00
|
|
|
echo "usage: $0 [-c] <filename>"
|
2011-12-30 21:12:15 +01:00
|
|
|
} >&2
|
2011-12-28 19:40:14 +01:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2012-04-09 17:59:36 +02:00
|
|
|
exec bats-exec-test $count_only "$(expand_path "$filename")" "$@"
|