2012-11-16 21:25:45 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2013-10-21 18:32:09 +02:00
|
|
|
count_only_flag=""
|
2012-11-16 21:25:45 +01:00
|
|
|
if [ "$1" = "-c" ]; then
|
2013-10-21 18:32:09 +02:00
|
|
|
count_only_flag=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
extended_syntax_flag=""
|
|
|
|
if [ "$1" = "-x" ]; then
|
|
|
|
extended_syntax_flag="-x"
|
2012-11-16 21:25:45 +01:00
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
trap "kill 0; exit 1" int
|
|
|
|
|
|
|
|
count=0
|
|
|
|
for filename in "$@"; do
|
2013-10-29 03:01:51 +01:00
|
|
|
let count+="$(bats-exec-test -c "$filename")"
|
2012-11-16 21:25:45 +01:00
|
|
|
done
|
|
|
|
|
2013-10-21 18:32:09 +02:00
|
|
|
if [ -n "$count_only_flag" ]; then
|
2012-11-16 21:25:45 +01:00
|
|
|
echo "$count"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "1..$count"
|
|
|
|
status=0
|
|
|
|
offset=0
|
|
|
|
for filename in "$@"; do
|
|
|
|
index=0
|
|
|
|
{
|
|
|
|
IFS= read -r # 1..n
|
|
|
|
while IFS= read -r line; do
|
|
|
|
case "$line" in
|
2013-10-21 18:32:09 +02:00
|
|
|
"begin "* )
|
2013-10-29 03:01:51 +01:00
|
|
|
let index+=1
|
2012-11-16 21:25:45 +01:00
|
|
|
echo "${line/ $index / $(($offset + $index)) }"
|
2013-10-21 18:32:09 +02:00
|
|
|
;;
|
|
|
|
"ok "* | "not ok "* )
|
2013-10-29 03:01:51 +01:00
|
|
|
[ -n "$extended_syntax_flag" ] || let index+=1
|
2013-10-21 18:32:09 +02:00
|
|
|
echo "${line/ $index / $(($offset + $index)) }"
|
2012-11-16 21:25:45 +01:00
|
|
|
[ "${line:0:6}" != "not ok" ] || status=1
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "$line"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2013-10-21 18:32:09 +02:00
|
|
|
} < <( bats-exec-test $extended_syntax_flag "$filename" )
|
2012-11-16 21:25:45 +01:00
|
|
|
offset=$(($offset + $index))
|
|
|
|
done
|
|
|
|
|
|
|
|
exit "$status"
|