ctdb-tests: Add simple test harnesses for running unit tests
authorAmitay Isaacs <amitay@gmail.com>
Mon, 6 Jul 2015 04:45:23 +0000 (14:45 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 9 Jul 2015 04:23:21 +0000 (06:23 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tests/scripts/unit.sh

index 44675ae1c7a0c0e1b4b6bc2354817e47860ea4e3..46ae876e4a10d7e4d36ccbac910bd3e8e5a3cfeb 100644 (file)
@@ -156,6 +156,54 @@ test_fail ()
     return 1
 }
 
+test_header_default ()
+{
+    echo "=================================================="
+    echo "Running \"$*\""
+}
+
+reset_test_header ()
+{
+    # Re-define this function to get different header
+    test_header ()
+    {
+        test_header_default "$@"
+    }
+}
+
+reset_test_header
+
+# Simple test harness for running binary unit tests
+unit_test ()
+{
+    test_header "$@"
+
+    _wrapper="$VALGRIND"
+    if $TEST_COMMAND_TRACE ; then
+       _wrapper="strace"
+    fi
+    _out=$($_wrapper "$@" 2>&1)
+
+    result_check || exit $?
+}
+
+# Simple test harness for running shell script unit tests
+script_test ()
+{
+    test_header "$@"
+
+    _shell=""
+    if ${TEST_COMMAND_TRACE} ; then
+       _shell="sh -x"
+    else
+       _shell="sh"
+    fi
+
+    _out=$($_shell "$@" 2>&1)
+
+    result_check || exit $?
+}
+
 local="${TEST_SUBDIR}/scripts/local.sh"
 if [ -r "$local" ] ; then
     . "$local"