From 37fcc53b26f0e619df4de7a2249c1ba60e109694 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 29 Jun 2010 08:00:24 +0200 Subject: [PATCH] BUG: test_todo_session with error exit doesn't work BUG 1: didn't report non-error exit A test that enforces a non-zero exit code via "=== N" would succeed when the command under test returned with success (0); only differing exit codes would be correctly reported. Corrected logic so that the check for the exit code would always run, not just when the command under test failed. BUG 2: too early evaluation of $? In the test expression, the evaluation of $? must be deferred until the test expression itself is evaluated. Escaping $? to prevent premature evaluation in the context of the expression definition. --- tests/test-lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 34cd9e4..efe8960 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -542,7 +542,7 @@ test_todo_session () { if [ $status = 0 ]; then test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output" else - test_expect_success "$1 $subnum" "$cmd > output || test $? = $status && test_cmp expect output" + test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output" fi subnum=$(($subnum + 1)) @@ -560,7 +560,7 @@ test_todo_session () { if [ $status = 0 ]; then test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output" else - test_expect_success "$1 $subnum" "$cmd > output || test $? = $status && test_cmp expect output" + test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output" fi fi }