ctdb:tests: Rework unit test result filtering
authorMartin Schwenke <martin@meltin.net>
Fri, 15 Nov 2013 01:22:05 +0000 (12:22 +1100)
committerMichael Adam <obnox@samba.org>
Wed, 27 Nov 2013 17:46:17 +0000 (18:46 +0100)
Using a variable is too fragile, so use a function instead.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/tests/eventscripts/scripts/local.sh
ctdb/tests/scripts/unit.sh
ctdb/tests/takeover/scripts/local.sh
ctdb/tests/tool/scripts/local.sh

index 4c3f0b1394f65a53303cda01f8d754f02586ee6f..2b4bc920462d3766d1c3b4173be0ed573ea93b56 100644 (file)
@@ -1012,11 +1012,7 @@ iterate_test ()
        _out=$($_shell "${CTDB_BASE}/events.d/$script" "$event" $args 2>&1)
        _rc=$?
 
-    if [ -n "$OUT_FILTER" ] ; then
-       _fout=$(echo "$_out" | eval sed -r $OUT_FILTER)
-    else
-       _fout="$_out"
-    fi
+       _fout=$(echo "$_out" | result_filter)
 
        if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
            _passed=true
index c7c2b7a27363156f089f3a31346f9aff46d17432..f423db19a2e0e6853521743e46a82528a9adfa4d 100644 (file)
@@ -113,17 +113,29 @@ EOF
     fi
 }
 
+# Result filtering is (usually) used to replace the date/time/PID
+# prefix on some CTDB tool/client log messages with the literal string
+# "DATE TIME [PID]".  This allows tests to loosely match this output,
+# since it can't otherwise be matched.
+result_filter_default ()
+{
+    _date_time_pid='[0-9/][0-9/]*\ [0-9:\.][0-9:\.]*\ \[[\ 0-9][\ 0-9]*\]'
+    sed -e "s@^${_date_time_pid}:@DATE\ TIME\ \[PID\]:@"
+}
+
+# Override this function to customise output filtering.
+result_filter ()
+{
+    result_filter_default
+}
+
 result_check ()
 {
     _rc=$?
 
     _extra_header="$1"
 
-    if [ -n "$OUT_FILTER" ] ; then
-       _fout=$(echo "$_out" | eval sed -r $OUT_FILTER)
-    else
-       _fout="$_out"
-    fi
+    _fout=$(echo "$_out" | result_filter)
 
     if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
        _passed=true
index 3b69d14fc92f7b7587eff5038b63159bb4123e70..b10d7461ee40fed25007dd705d7284390fd6abea 100644 (file)
@@ -17,9 +17,6 @@ define_test ()
 
 simple_test ()
 {
-    # Do some filtering of the output to replace date/time.
-    OUT_FILTER='s@^[^\]]*\]:@DATE\ TIME\ \[PID\]:@'
-
     _out=$($VALGRIND $test_prog "$@" 2>&1)
 
     result_check "Algorithm: $CTDB_IP_ALGORITHM"
index 385e2ad64b4d997f11e3c5a7eff760593de11f98..6cad929e85e7b3705dfaf054206ca098c060d083 100644 (file)
@@ -44,12 +44,6 @@ setup_natgw ()
 
 simple_test ()
 {
-    # Most of the tests when the tool fails will have a date/time/pid
-    # prefix.  Strip that because it isn't possible to match it.
-    if [ $required_rc -ne 0 ]  ; then
-       OUT_FILTER='s@^[0-9/]+\ [0-9:\.]+\ \[[\ 0-9]+\]:@DATE\ TIME\ \[PID\]:@'
-    fi
-
     _out=$($VALGRIND $test_prog "$@" 2>&1)
 
     result_check