mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 11:42:33 +01:00
f5acd28612
Under Bash 3.2.57(1)-release and 4.4.12(1)-release on a MacBook Pro with a 2.9GHz Intel Core i5 CPU and 8GB 1867MHz DDR3 RAM, this shaves off O(0.16s) from the current test suite. Before this change: 46 tests, 0 failures real 0m3.541s user 0m2.125s sys 0m0.937s After this change: real 0m3.372s user 0m2.031s sys 0m0.894s
60 lines
1.1 KiB
Bash
Executable File
60 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
count_only_flag=""
|
|
if [ "$1" = "-c" ]; then
|
|
count_only_flag=1
|
|
shift
|
|
fi
|
|
|
|
extended_syntax_flag=""
|
|
if [ "$1" = "-x" ]; then
|
|
extended_syntax_flag="-x"
|
|
shift
|
|
fi
|
|
|
|
trap "kill 0; exit 1" int
|
|
|
|
count=0
|
|
for filename in "$@"; do
|
|
while IFS= read -r line; do
|
|
if [[ "$line" =~ $BATS_TEST_PATTERN ]]; then
|
|
let count+=1
|
|
fi
|
|
done <"$filename"
|
|
done
|
|
|
|
if [ -n "$count_only_flag" ]; then
|
|
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
|
|
"begin "* )
|
|
let index+=1
|
|
echo "${line/ $index / $(($offset + $index)) }"
|
|
;;
|
|
"ok "* | "not ok "* )
|
|
[ -n "$extended_syntax_flag" ] || let index+=1
|
|
echo "${line/ $index / $(($offset + $index)) }"
|
|
[ "${line:0:6}" != "not ok" ] || status=1
|
|
;;
|
|
* )
|
|
echo "$line"
|
|
;;
|
|
esac
|
|
done
|
|
} < <( bats-exec-test $extended_syntax_flag "$filename" )
|
|
offset=$(($offset + $index))
|
|
done
|
|
|
|
exit "$status"
|