]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] color-coded test output
authorEvan Hunt <each@isc.org>
Fri, 29 Sep 2017 19:20:55 +0000 (12:20 -0700)
committerEvan Hunt <each@isc.org>
Fri, 29 Sep 2017 19:20:55 +0000 (12:20 -0700)
4745. [test] Add color-coded pass/fail messages to system
tests when running on terminals that support them.
[RT #45977]

CHANGES
bin/tests/system/conf.sh.in
bin/tests/system/run.sh

diff --git a/CHANGES b/CHANGES
index ff3b6a1c1c5722f6117039c45e949b7da1693bcd..6dfe84a3b2dba078233ee5ac3df0176fe1c3b30d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+4745.  [test]          Add color-coded pass/fail messages to system
+                       tests when running on terminals that support them.
+                       [RT #45977]
+
 4744.  [bug]           Suppress trust-anchor-telementry queries if
                        validation is disabled. [RT #46131]
 
index 0d63f129e8ad34e5354c1f0cbd26342e92a99a30..5e05378321e5ac0cf79f7e65f607aa277ef56426 100644 (file)
@@ -135,6 +135,43 @@ NZD=@NZD_TOOLS@
 
 . ${TOP}/version
 
+#
+# Set up color-coded test output
+#
+if test -t 1 && type tput > /dev/null; then
+    COLOR_FAIL=`tput setaf 1`   # red
+    COLOR_WARN=`tput setaf 3`   # yellow
+    COLOR_PASS=`tput setaf 2`   # green
+    COLOR_INFO=`tput bold`      # bold
+    COLOR_NONE=`tput sgr0`
+else
+    # set to empty strings so printf succeeds
+    COLOR_FAIL=''
+    COLOR_WARN=''
+    COLOR_PASS=''
+    COLOR_INFO=''
+    COLOR_NONE=''
+fi
+
+echofail () {
+        printf "${COLOR_FAIL}%s${COLOR_NONE}\n" "$*"
+}
+
+echowarn () {
+        printf "${COLOR_WARN}%s${COLOR_NONE}\n" "$*"
+}
+
+echopass () {
+        printf "${COLOR_PASS}%s${COLOR_NONE}\n" "$*"
+}
+
+echoinfo () {
+        printf "${COLOR_INFO}%s${COLOR_NONE}\n" "$*"
+}
+
+#
+# Export command paths
+#
 export ARPANAME
 export BIGKEY
 export CHECKZONE
index 150f3b505bd30446d0719b00f2cf77303e5bc25c..f8175278a5d5e5f9a835f3dd243fc87424863d7d 100644 (file)
@@ -28,22 +28,22 @@ shift
 
 test -d $test || { echo "$0: $test: no such test" >&2; exit 1; }
 
-echo "S:$test:`date`" >&2
-echo "T:$test:1:A" >&2
-echo "A:System test $test" >&2
+echoinfo "S:$test:`date`" >&2
+echoinfo "T:$test:1:A" >&2
+echoinfo "A:System test $test" >&2
 
 if [ x${PERL:+set} = x ]
 then
-    echo "I:Perl not available.  Skipping test." >&2
-    echo "R:UNTESTED" >&2
-    echo "E:$test:`date`" >&2
+    echowarn "I:Perl not available.  Skipping test." >&2
+    echowarn "R:UNTESTED" >&2
+    echoinfo "E:$test:`date`" >&2
     exit 0;
 fi
 
 $PERL testsock.pl || {
-    echo "I:Network interface aliases not set up.  Skipping test." >&2;
-    echo "R:UNTESTED" >&2;
-    echo "E:$test:`date`" >&2;
+    echowarn "I:Network interface aliases not set up.  Skipping test." >&2;
+    echowarn "R:UNTESTED" >&2;
+    echoinfo "E:$test:`date`" >&2;
     exit 0;
 }
 
@@ -55,9 +55,9 @@ result=$?
 if [ $result -eq 0 ]; then
     : prereqs ok
 else
-    echo "I:Prerequisites for $test missing, skipping test." >&2
-    [ $result -eq 255 ] && echo "R:SKIPPED" || echo "R:UNTESTED"
-    echo "E:$test:`date`" >&2
+    echowarn "I:Prerequisites for $test missing, skipping test." >&2
+    [ $result -eq 255 ] && echowarn "R:SKIPPED" || echowarn "R:UNTESTED"
+    echoinfo "E:$test:`date`" >&2
     exit 0
 fi
 
@@ -67,9 +67,9 @@ if
 then
     : pkcs11 ok
 else
-    echo "I:Need PKCS#11 for $test, skipping test." >&2
-    echo "R:PKCS11ONLY" >&2
-    echo "E:$test:`date`" >&2
+    echowarn "I:Need PKCS#11 for $test, skipping test." >&2
+    echowarn "R:PKCS11ONLY" >&2
+    echoinfo "E:$test:`date`" >&2
     exit 0
 fi
 
@@ -80,7 +80,7 @@ then
 fi
 
 # Start name servers running
-$PERL start.pl $test || { echo "R:FAIL"; echo "E:$test:`date`"; exit 1; }
+$PERL start.pl $test || { echofail "R:FAIL"; echoinfo "E:$test:`date`"; exit 1; }
 
 # Run the tests
 ( cd $test ; $SHELL tests.sh )
@@ -100,11 +100,11 @@ $PERL stop.pl $test
 status=`expr $status + $?`
 
 if [ $status != 0 ]; then
-       echo "R:FAIL"
+       echofail "R:FAIL"
        # Don't clean up - we need the evidence.
        find . -name core -exec chmod 0644 '{}' \;
 else
-       echo "R:PASS"
+       echopass "R:PASS"
 
        if $clean
        then
@@ -122,6 +122,6 @@ else
        fi
 fi
 
-echo "E:$test:`date`"
+echoinfo "E:$test:`date`"
 
 exit $status