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

exec-test: Replace caller with FUNCNAME, etc.

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

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 makes `bin/bats test/` go from the
following for the previous commit:

  44 tests, 0 failures

  real    0m5.293s
  user    0m2.853s
  sys     0m2.087s

to:

  real    0m4.319s
  user    0m2.559s
  sys     0m1.454s
This commit is contained in:
Mike Bland 2017-02-15 11:23:28 -05:00
parent e613b31a1c
commit fac51df957
No known key found for this signature in database
GPG Key ID: 5121C73A6E07384B

View File

@ -101,16 +101,15 @@ bats_capture_stack_trace() {
local teardown_pattern=" teardown $BATS_TEST_SOURCE"
local frame
local index=1
local i
while frame="$(caller "$index")"; do
for ((i=2; i != ${#FUNCNAME[@]}; ++i)); do
frame="${BASH_LINENO[$((i-1))]} ${FUNCNAME[$i]} ${BASH_SOURCE[$i]}"
BATS_CURRENT_STACK_TRACE["${#BATS_CURRENT_STACK_TRACE[@]}"]="$frame"
if [[ "$frame" = *"$test_pattern" || \
"$frame" = *"$setup_pattern" || \
"$frame" = *"$teardown_pattern" ]]; then
break
else
let index+=1
fi
done