From f5acd286129e3b68945a33da7d74ece82564ac57 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Thu, 16 Mar 2017 14:10:19 -0400 Subject: [PATCH] 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 --- libexec/bats | 1 + libexec/bats-exec-suite | 6 +++++- libexec/bats-preprocess | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libexec/bats b/libexec/bats index 7dc0c14..e074747 100755 --- a/libexec/bats +++ b/libexec/bats @@ -77,6 +77,7 @@ abs_dirname '.' 'BATS_CWD' export BATS_PREFIX export BATS_CWD +export BATS_TEST_PATTERN='^ *@test +(.+) +\{ *(.*)$' export PATH="$BATS_LIBEXEC:$PATH" options=() diff --git a/libexec/bats-exec-suite b/libexec/bats-exec-suite index 29ab255..96021bb 100755 --- a/libexec/bats-exec-suite +++ b/libexec/bats-exec-suite @@ -17,7 +17,11 @@ trap "kill 0; exit 1" int count=0 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 if [ -n "$count_only_flag" ]; then diff --git a/libexec/bats-preprocess b/libexec/bats-preprocess index 30392b6..8307b76 100755 --- a/libexec/bats-preprocess +++ b/libexec/bats-preprocess @@ -33,12 +33,11 @@ encode_name() { tests=() index=0 -pattern='^ *@test +(.+) +\{ *(.*)$' while IFS= read -r line; do line="${line//$'\r'}" let index+=1 - if [[ "$line" =~ $pattern ]]; then + if [[ "$line" =~ $BATS_TEST_PATTERN ]]; then name="${BASH_REMATCH[1]#[\'\"]}" name="${name%[\'\"]}" body="${BASH_REMATCH[2]}"