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

exec-test: Use printf -v in bats_frame_* functions

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:

  44 tests, 0 failures

  real    0m7.565s
  user    0m3.664s
  sys     0m3.368s

to:

  real    0m6.449s
  user    0m3.290s
  sys     0m2.665s
This commit is contained in:
Mike Bland 2017-02-14 16:37:35 -05:00
parent a3396cbc89
commit 93d3cec96f
No known key found for this signature in database
GPG Key ID: 5121C73A6E07384B

View File

@ -114,18 +114,21 @@ bats_capture_stack_trace() {
fi
done
BATS_SOURCE="$(bats_frame_filename "${BATS_CURRENT_STACK_TRACE[0]}")"
BATS_LINENO="$(bats_frame_lineno "${BATS_CURRENT_STACK_TRACE[0]}")"
bats_frame_filename "${BATS_CURRENT_STACK_TRACE[0]}" 'BATS_SOURCE'
bats_frame_lineno "${BATS_CURRENT_STACK_TRACE[0]}" 'BATS_LINENO'
}
bats_print_stack_trace() {
local frame
local index=1
local count="${#@}"
local filename
local lineno
for frame in "$@"; do
local filename="$(bats_trim_filename "$(bats_frame_filename "$frame")")"
local lineno="$(bats_frame_lineno "$frame")"
bats_frame_filename "$frame" 'filename'
filename="$(bats_trim_filename "$filename")"
bats_frame_lineno "$frame" 'lineno'
if [ $index -eq 1 ]; then
echo -n "# ("
@ -133,7 +136,8 @@ bats_print_stack_trace() {
echo -n "# "
fi
local fn="$(bats_frame_function "$frame")"
local fn
bats_frame_function "$frame" 'fn'
if [ "$fn" != "$BATS_TEST_NAME" ]; then
echo -n "from function \`$fn' "
fi
@ -151,8 +155,11 @@ bats_print_stack_trace() {
bats_print_failed_command() {
local frame="$1"
local status="$2"
local filename="$(bats_frame_filename "$frame")"
local lineno="$(bats_frame_lineno "$frame")"
local filename
local lineno
bats_frame_filename "$frame" 'filename'
bats_frame_lineno "$frame" 'lineno'
local failed_line="$(bats_extract_line "$filename" "$lineno")"
local failed_command="$(bats_strip_string "$failed_line")"
@ -166,12 +173,12 @@ bats_print_failed_command() {
}
bats_frame_lineno() {
printf '%s\n' "${1%% *}"
printf -v "$2" '%s' "${1%% *}"
}
bats_frame_function() {
local __bff_function="${1#* }"
printf '%s\n' "${__bff_function%% *}"
printf -v "$2" '%s' "${__bff_function%% *}"
}
bats_frame_filename() {
@ -181,7 +188,7 @@ bats_frame_filename() {
if [ "$__bff_filename" = "$BATS_TEST_SOURCE" ]; then
__bff_filename="$BATS_TEST_FILENAME"
fi
printf '%s\n' "$__bff_filename"
printf -v "$2" '%s' "$__bff_filename"
}
bats_extract_line() {