1
0
mirror of https://github.com/sstephenson/bats.git synced 2025-03-03 15:29:52 +01:00

format-tap: Refactor summary to remove subshells

While the performance impact of these changes are in the noise under
macOS 10.12.3 on a on a MacBook Pro with a 2.9GHz Intel Core i5 CPU and
8GB 1867MHz DDR3 RAM, eliminating these subshells makes the code more
consistent.

I did try removing `buffer` to eliminate yet more subshells, but the
flickering of the output did prove annoying, so I'm not removing it.
This commit is contained in:
Mike Bland 2017-03-16 16:04:54 -04:00
parent f5acd28612
commit 8c4a86d534
No known key found for this signature in database
GPG Key ID: 5121C73A6E07384B

View File

@ -65,9 +65,15 @@ log() {
}
summary() {
printf "\n%d test%s" "$count" "$(plural "$count")"
printf "\n%d test" "$count"
if [[ "$count" -ne '1' ]]; then
printf 's'
fi
printf ", %d failure%s" "$failures" "$(plural "$failures")"
printf ", %d failure" "$failures"
if [[ "$failures" -ne '1' ]]; then
printf 's'
fi
if [ "$skipped" -gt 0 ]; then
printf ", %d skipped" "$skipped"
@ -79,7 +85,9 @@ summary() {
printf_with_truncation() {
local width="$1"
shift
local string="$(printf "$@")"
local string
printf -v 'string' -- "$@"
if [ "${#string}" -gt "$width" ]; then
printf "%s..." "${string:0:$(( $width - 4 ))}"
@ -105,18 +113,18 @@ advance() {
set_color() {
local color="$1"
local weight="$2"
printf "\x1B[%d;%dm" $(( 30 + $color )) "$( [ "$weight" = "bold" ] && echo 1 || echo 22 )"
local weight='22'
if [[ "$2" == 'bold' ]]; then
weight='1'
fi
printf "\x1B[%d;%dm" $(( 30 + $color )) "$weight"
}
clear_color() {
printf "\x1B[0m"
}
plural() {
[ "$1" -eq 1 ] || echo "s"
}
_buffer=""
buffer() {