mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 11:42:33 +01:00
74 lines
1.3 KiB
Bash
Executable File
74 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
version() {
|
|
echo "Bats 0.2.0"
|
|
}
|
|
|
|
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"
|
|
|
|
if [ "$1" = "-v" ] || [ "$1" = "--version" ]; then
|
|
version
|
|
exit 0
|
|
fi
|
|
|
|
count_only=""
|
|
if [ "$1" = "-c" ]; then
|
|
count_only="-c"
|
|
shift
|
|
fi
|
|
|
|
if [ -z "$1" ]; then
|
|
{ version
|
|
echo "usage: $0 [-c] <filename> [<filename> ...]"
|
|
} >&2
|
|
exit 1
|
|
fi
|
|
|
|
filenames=()
|
|
for filename in "$@"; do
|
|
if [ -d "$filename" ]; then
|
|
shopt -s nullglob
|
|
for suite_filename in "$(expand_path "$filename")"/*.bats; do
|
|
filenames["${#filenames[@]}"]="$suite_filename"
|
|
done
|
|
shopt -u nullglob
|
|
else
|
|
filenames["${#filenames[@]}"]="$(expand_path "$filename")"
|
|
fi
|
|
done
|
|
|
|
if [ "${#filenames[@]}" -eq 1 ]; then
|
|
exec bats-exec-test $count_only "${filenames[0]}"
|
|
else
|
|
exec bats-exec-suite $count_only "${filenames[@]}"
|
|
fi
|