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.
This commit is contained in:
Ingo Karkat
2010-06-29 08:00:24 +02:00
parent e7b5841721
commit 37fcc53b26

View File

@@ -542,7 +542,7 @@ test_todo_session () {
if [ $status = 0 ]; then if [ $status = 0 ]; then
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output" test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
else 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
subnum=$(($subnum + 1)) subnum=$(($subnum + 1))
@@ -560,7 +560,7 @@ test_todo_session () {
if [ $status = 0 ]; then if [ $status = 0 ]; then
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output" test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
else 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
fi fi
} }