Test suite: add a -d option to the run_tests script.
authorMartin Schwenke <martin@meltin.net>
Mon, 23 May 2011 05:41:59 +0000 (15:41 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 3 Aug 2011 05:51:44 +0000 (15:51 +1000)
This causes summary lines (when used with -s) to be pretty printed and
include the test description.  This is the 4th line of the test output
- that is, immediately after the header.

Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/scripts/run_tests

index 8a878593521758b20c4eb133f7c5c868544cce88..5906c4281423cb4409d1a5d6ba9bfabe8a763091 100755 (executable)
@@ -18,8 +18,9 @@ EOF
 ######################################################################
 
 with_summary=false
+with_desc=false
 
-temp=$(getopt -n "$prog" -o "xhs" -l help -- "$@")
+temp=$(getopt -n "$prog" -o "xdhs" -l help -- "$@")
 
 [ $? != 0 ] && usage
 
@@ -28,6 +29,7 @@ eval set -- "$temp"
 while true ; do
     case "$1" in
        -x) set -x; shift ;;
+       -d) with_desc=true ; shift ;;  # 4th line of output is description
        -s) with_summary=true ; shift ;;
        --) shift ; break ;;
        *) usage ;;
@@ -43,18 +45,31 @@ summary=""
 rows=$(if tty -s ; then stty size ; else echo x 80 ; fi | sed -e 's@.* @@' -e 's@^0$@80@')
 ww=$((rows - 7))
 
+tf=$(mktemp)
+
+set -o pipefail
+
 for f; do
     [ -x $f ] || fail "test \"$f\" is not executable"
     tests_total=$(($tests_total + 1))
-    if ctdb_test_run "$f" ; then
+    ctdb_test_run "$f" | tee "$tf"
+    status=$?
+    if [ $status -eq 0 ] ; then
        tests_passed=$(($tests_passed + 1))
        t="PASSED"
     else
        t="FAILED"
     fi
+    if $with_desc ; then
+       f="${f#./}" ; f="${f%%[./]*}"
+       desc=$(tail -n +4 $tf | head -n 1)
+       f="${f} ${desc}"
+    fi
     summary=$(printf "%s\n%-${ww}s%s" "$summary" "$f" "$t")
 done
 
+rm -f "$tf"
+
 if $with_summary ; then
     echo "$summary"
     echo