diff --git a/ctdb/tests/scripts/unit.sh b/ctdb/tests/scripts/unit.sh index 8affe702aaf..363f5ca6905 100644 --- a/ctdb/tests/scripts/unit.sh +++ b/ctdb/tests/scripts/unit.sh @@ -12,240 +12,241 @@ trap -- '' PIPE # indicates empty output. # If argument 2 is not present or null then read required test output # from stdin. -required_result () +required_result() { - required_rc="${1:-0}" - if [ -n "$2" ] ; then - if [ "$2" = "--" ] ; then - required_output="" + required_rc="${1:-0}" + if [ -n "$2" ]; then + if [ "$2" = "--" ]; then + required_output="" + else + required_output="$2" + fi else - required_output="$2" + if ! tty -s; then + required_output=$(cat) + else + required_output="" + fi fi - else - if ! tty -s ; then - required_output=$(cat) - else - required_output="" - fi - fi } -required_error () +required_error() { rc=$(errcode "$1") shift required_result "$rc" "$@" } -ok () +ok() { - required_result 0 "$@" + required_result 0 "$@" } -ok_null () +ok_null() { - ok -- + ok -- } -reset_extra_header () +reset_extra_header() { - # Re-define this function to output extra header information - extra_header () - { - : - } + # Re-define this function to output extra header information + extra_header() + { + : + } } -reset_extra_footer () +reset_extra_footer() { - # Re-define this function to output extra footer information - extra_footer () - { - : - } + # Re-define this function to output extra footer information + extra_footer() + { + : + } } reset_extra_header reset_extra_footer -result_print () +result_print() { - _passed="$1" - _out="$2" - _rc="$3" + _passed="$1" + _out="$2" + _rc="$3" - if "$CTDB_TEST_VERBOSE" || ! $_passed ; then - extra_header + if "$CTDB_TEST_VERBOSE" || ! $_passed; then + extra_header -cat <"$_outr" + if $CTDB_TEST_DIFF_RESULTS; then + _outr=$(mktemp) + # Avoid echo, which might expand unintentional escapes + printf '%s\n' "$required_output" >"$_outr" - _outf=$(mktemp) - # Avoid echo, which might expand unintentional escapes - printf '%s\n' "$_fout" >"$_outf" + _outf=$(mktemp) + # Avoid echo, which might expand unintentional escapes + printf '%s\n' "$_fout" >"$_outf" - cat <&1) + _wrapper="$VALGRIND" + if $CTDB_TEST_COMMAND_TRACE; then + _wrapper="strace" + fi + _out=$($_wrapper "$@" 2>&1) - result_check || exit $? + result_check || exit $? } # Simple test harness for running shell script unit tests -script_test () +script_test() { - test_header "$@" + test_header "$@" - _shell="" - if ${CTDB_TEST_COMMAND_TRACE} ; then - _shell="sh -x" - else - _shell="sh" - fi + _shell="" + if ${CTDB_TEST_COMMAND_TRACE}; then + _shell="sh -x" + else + _shell="sh" + fi - _out=$($_shell "$@" 2>&1) + _out=$($_shell "$@" 2>&1) - result_check || exit $? + result_check || exit $? } # Simple test harness for running tests without tracing -unit_test_notrace () +unit_test_notrace() { - test_header "$@" + test_header "$@" - _out=$("$@" 2>&1) + _out=$("$@" 2>&1) - result_check || exit $? + result_check || exit $? } test_cleanup_hooks="" -test_cleanup () +test_cleanup() { - test_cleanup_hooks="${test_cleanup_hooks}${test_cleanup_hooks:+ ; }$*" + test_cleanup_hooks="${test_cleanup_hooks}${test_cleanup_hooks:+ ; }$*" } trap 'eval $test_cleanup_hooks' 0 local="${CTDB_TEST_SUITE_DIR}/scripts/local.sh" -if [ -r "$local" ] ; then - . "$local" +if [ -r "$local" ]; then + . "$local" fi