mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 19:52:37 +01:00
bats-exec-suite: Count tests w/ BATS_TEST_PATTERN
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
This commit is contained in:
parent
7bcbb2f3e9
commit
f5acd28612
|
@ -77,6 +77,7 @@ abs_dirname '.' 'BATS_CWD'
|
||||||
|
|
||||||
export BATS_PREFIX
|
export BATS_PREFIX
|
||||||
export BATS_CWD
|
export BATS_CWD
|
||||||
|
export BATS_TEST_PATTERN='^ *@test +(.+) +\{ *(.*)$'
|
||||||
export PATH="$BATS_LIBEXEC:$PATH"
|
export PATH="$BATS_LIBEXEC:$PATH"
|
||||||
|
|
||||||
options=()
|
options=()
|
||||||
|
|
|
@ -17,7 +17,11 @@ trap "kill 0; exit 1" int
|
||||||
|
|
||||||
count=0
|
count=0
|
||||||
for filename in "$@"; do
|
for filename in "$@"; do
|
||||||
let count+="$(bats-exec-test -c "$filename")"
|
while IFS= read -r line; do
|
||||||
|
if [[ "$line" =~ $BATS_TEST_PATTERN ]]; then
|
||||||
|
let count+=1
|
||||||
|
fi
|
||||||
|
done <"$filename"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$count_only_flag" ]; then
|
if [ -n "$count_only_flag" ]; then
|
||||||
|
|
|
@ -33,12 +33,11 @@ encode_name() {
|
||||||
|
|
||||||
tests=()
|
tests=()
|
||||||
index=0
|
index=0
|
||||||
pattern='^ *@test +(.+) +\{ *(.*)$'
|
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
line="${line//$'\r'}"
|
line="${line//$'\r'}"
|
||||||
let index+=1
|
let index+=1
|
||||||
if [[ "$line" =~ $pattern ]]; then
|
if [[ "$line" =~ $BATS_TEST_PATTERN ]]; then
|
||||||
name="${BASH_REMATCH[1]#[\'\"]}"
|
name="${BASH_REMATCH[1]#[\'\"]}"
|
||||||
name="${name%[\'\"]}"
|
name="${name%[\'\"]}"
|
||||||
body="${BASH_REMATCH[2]}"
|
body="${BASH_REMATCH[2]}"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user