Permalink
Browse files

test-report: Use color highlighting as in test-lib.

The test aggregate results are easy to miss when running the entire test suite via "make test", as the status of the last test case is highlighted, but the aggregate results appear in an unformatted, uncolored block of text.
Copy the say_color() function from test-lib.sh. (Sorry for the duplication, I found no simple way to import or share just this piece of functionality without adding much complexity.)
Successes, errors and broken summaries will now be highlighted in the appropriate colors (unless --no-color is given or output is not to a terminal), but only if the number is more than zero.
  • Loading branch information...
1 parent ebe9fb8 commit c31716af470ff9267b12965288e967aadecf5aad @inkarkat inkarkat committed Jan 26, 2012
Showing with 59 additions and 6 deletions.
  1. +59 −6 tests/aggregate-results.sh
View
@@ -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)"

0 comments on commit c31716a

Please sign in to comment.