Tests - eventscripts - add extra filename format for multi-event tests
authorMartin Schwenke <martin@meltin.net>
Tue, 30 Aug 2011 04:19:09 +0000 (14:19 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 30 Aug 2011 06:51:55 +0000 (16:51 +1000)
$event may not be set so we need to test for it.

Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/eventscripts/common.sh

index 070aa45a059a3488ec139de1d08127629d190018..4c80a95868de613dd265d4db5aaf413c9a0a30cd 100644 (file)
@@ -598,16 +598,27 @@ define_test ()
     desc="$1"
 
     _f="$0"
-    _f="${_f#./}"      # strip leading ./
-    _f="${_f#simple/}" # strip leading simple/
-    _f="${_f%%/*}"     # if subdir, strip off file
-    _f="${_f%.sh}"     # strip off .sh suffix if any
+    _f="${_f#./}"          # strip leading ./
+    _f="${_f#simple/}"     # strip leading simple/
+    _f="${_f#multievent/}" # strip leading multievent/
+    _f="${_f%%/*}"         # if subdir, strip off file
+    _f="${_f%.sh}"         # strip off .sh suffix if any
 
-    # Remaining format should be NN.service.event.NNN:
+    # Remaining format should be NN.service.event.NNN or NN.service.NNN:
     _num="${_f##*.}"
     _f="${_f%.*}"
-    event="${_f##*.}"
-    script="${_f%.*}"
+    case "$_f" in
+       *.*.*)
+           script="${_f%.*}"
+           event="${_f##*.}"
+           ;;
+       *.*)
+           script="$_f"
+           unset event
+           ;;
+       *)
+           die "Internal error - unknown testcase filename format"
+    esac
 
     printf "%-14s %-10s %-4s - %s\n\n" "$script" "$event" "$_num" "$desc"
 }
@@ -719,6 +730,8 @@ EOF
 # useful for debugging.
 simple_test ()
 {
+    [ -n "$event" ] || die 'simple_test: $event not set'
+
     echo "Running \"${CTDB_BASE}/events.d/$script $event\""
     _out=$($EVENTSCRIPTS_TESTS_TRACE "${CTDB_BASE}/events.d/$script" "$event" "$@" 2>&1)
     _rc=$?
@@ -759,6 +772,8 @@ simple_test ()
 # iteration.
 iterate_test ()
 {
+    [ -n "$event" ] || die 'simple_test: $event not set'
+
     args=""
     if [ "$1" = "--" ] ; then
        shift