1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-11-17 11:42:33 +01:00

preprocess: Eliminate eval in subshell

This is part of the effort to improve performance by reducing the number
of command substitutions/subshells.

Under Bash 3.2.57(1)-release on a MacBook Pro with a 2.9GHz Intel Core
i5 CPU and 8GB 1867MHz DDR3 RAM, this shaves off O(0.15s) from the test
suite at the previous commit, but I anticipate this effect being
magnified on Windows platforms.
This commit is contained in:
Mike Bland 2017-02-15 11:53:01 -05:00
parent 3ab495fda2
commit 6beea07a0b
No known key found for this signature in database
GPG Key ID: 5121C73A6E07384B
3 changed files with 6 additions and 6 deletions

View File

@ -33,18 +33,18 @@ encode_name() {
tests=()
index=0
pattern='^ *@test *([^ ].*) *\{ *(.*)$'
pattern='^ *@test +(.+) +\{ *(.*)$'
while IFS= read -r line; do
line="${line//$'\r'}"
let index+=1
if [[ "$line" =~ $pattern ]]; then
quoted_name="${BASH_REMATCH[1]}"
name="${BASH_REMATCH[1]#[\'\"]}"
name="${name%[\'\"]}"
body="${BASH_REMATCH[2]}"
name="$(eval echo "$quoted_name")"
encode_name "$name" 'encoded_name'
tests["${#tests[@]}"]="$encoded_name"
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
echo "${encoded_name}() { bats_test_begin \"${name}\" ${index}; ${body}"
else
printf "%s\n" "$line"
fi

View File

@ -280,5 +280,5 @@ fixtures bats
[ $status -eq 0 ]
[ "${lines[1]}" = "ok 1 single-quoted name" ]
[ "${lines[2]}" = "ok 2 double-quoted name" ]
[ "${lines[3]}" = "ok 3 unquoted" ]
[ "${lines[3]}" = "ok 3 unquoted name" ]
}

View File

@ -6,6 +6,6 @@
true
}
@test unquoted {
@test unquoted name {
true
}