From 189779c6de52efca7f783478fb25022bcb7be776 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 25 Jan 2012 15:23:57 +0100 Subject: [PATCH] test-lib: Separate function for exit code assertion. Remove the check for the todo.sh exit code (scripted via "=== N") from the command under test into a separate assertion test_expect_code_and_output. This allows for reporting of expected vs. actual exit code (also in the default non-verbose mode), and unexpected output from the same test is now reported, too. --- tests/test-lib.sh | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index e69f484..2368bd3 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -284,6 +284,33 @@ $cmp_output" echo >&3 "" } +test_expect_code_and_output () { + test "$#" = 3 || + error "bug in the test script: not 3 parameters to test-expect-code-and-output" + if ! test_skip "$@" + then + say >&3 "expecting exit code $1 and output: $3" + test_run_ "$3" + if [ "$?" = 0 -a "$eval_ret" = "$1" ] + then + cmp_output=$(test_cmp expect output) + if [ "$?" = 0 ] + then + test_ok_ "$2" + else + test_failure_ "$2" "$3" " +$cmp_output" + fi + else + cmp_output=$(test_cmp expect output) + test_failure_ "$2" "$3" " +* expected exit code $1, actual ${eval_ret}${cmp_output:+ +}${cmp_output}" + fi + fi + echo >&3 "" +} + test_expect_code () { test "$#" = 3 || error "bug in the test script: not 3 parameters to test-expect-code" @@ -295,7 +322,8 @@ test_expect_code () { then test_ok_ "$2" else - test_failure_ "$@" + test_failure_ "$2" "$3" " +* expected exit code $1, actual ${eval_ret}" fi fi echo >&3 "" @@ -568,7 +596,7 @@ test_todo_session () { if [ $status = 0 ]; then test_expect_output "$1 $subnum" "$cmd > output" else - test_expect_output "$1 $subnum" "$cmd > output ; test \$? = $status" + test_expect_code_and_output "$status" "$1 $subnum" "$cmd > output" fi subnum=$(($subnum + 1)) @@ -586,7 +614,7 @@ test_todo_session () { if [ $status = 0 ]; then test_expect_output "$1 $subnum" "$cmd > output" else - test_expect_output "$1 $subnum" "$cmd > output ; test \$? = $status" + test_expect_code_and_output "$status" "$1 $subnum" "$cmd > output" fi fi }