From 93dc2f08398e7c905195faef3882d3a253c7997a Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 6 Jul 2015 14:45:23 +1000 Subject: [PATCH] ctdb-tests: Add simple test harnesses for running unit tests Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/tests/scripts/unit.sh | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/ctdb/tests/scripts/unit.sh b/ctdb/tests/scripts/unit.sh index 44675ae1c7a..46ae876e4a1 100644 --- a/ctdb/tests/scripts/unit.sh +++ b/ctdb/tests/scripts/unit.sh @@ -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"