diff --git a/tests/aggregate-results.sh b/tests/aggregate-results.sh index d5bab75..ecc258f 100755 --- a/tests/aggregate-results.sh +++ b/tests/aggregate-results.sh @@ -1,4 +1,57 @@ -#!/bin/sh +#!/bin/bash + +[ "x$TERM" != "xdumb" ] && ( + export TERM && + [ -t 1 ] && + tput bold >/dev/null 2>&1 && + tput setaf 1 >/dev/null 2>&1 && + tput sgr0 >/dev/null 2>&1 + ) && + color=t + +case "$1" in +--no-color) + color=; shift ;; +esac + +if test -n "$color"; then + say_color () { + ( + export TERM + case "$1" in + error) tput bold; tput setaf 1;; # bold red + skip) tput bold; tput setaf 2;; # bold green + pass) tput setaf 2;; # green + info) tput setaf 3;; # brown + *) test -n "$quiet" && return;; + esac + shift + printf "* %s" "$*" + tput sgr0 + echo + ) + } +else + say_color() { + test -z "$1" && test -n "$quiet" && return + shift + echo "* $*" + } +fi + +get_color() +{ + # Only use the supplied color if there are actually instances of that + # type, so that a clean test run does not distract the user by the + # appearance of the error highlighting. + if [ ${1:?} -eq 0 ] + then + echo 'info' + else + echo "${2:-info}" + fi +} + fixed=0 success=0 @@ -27,8 +80,8 @@ do done <"$file" done -printf "%-8s%d\n" fixed $fixed -printf "%-8s%d\n" success $success -printf "%-8s%d\n" failed $failed -printf "%-8s%d\n" broken $broken -printf "%-8s%d\n" total $total +say_color 'info' "$(printf "%-8s%d\n" fixed $fixed)" +say_color "$(get_color "$success" 'pass')" "$(printf "%-8s%d\n" success $success)" +say_color "$(get_color "$failed" 'error')" "$(printf "%-8s%d\n" failed $failed)" +say_color "$(get_color "$broken" 'error')" "$(printf "%-8s%d\n" broken $broken)" +say_color 'info' "$(printf "%-8s%d\n" total $total)"