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