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 }