t: wrap complicated expect_code users in a block
If we are expecting a command to produce a particular exit code, we can use test_expect_code. However, some cases are more complicated, and want to accept one of a range of exit codes. For these, we end up with something like: cmd; case "$?" in ... That unfortunately breaks the &&-chain and fools --chain-lint. Since these special cases are so few, we can wrap them in a block, like this: { cmd; ret=$?; } && case "$ret" in ... This accomplishes the same thing, and retains the &&-chain (the exit status fed to the && is that of the assignment, which should always be true). It's technically longer, but it is probably a good thing for unusual code like this to stand out. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
c21fc9d0ab
commit
9ddc5ac97e
|
@ -10,8 +10,8 @@ one
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'sigchain works' '
|
test_expect_success 'sigchain works' '
|
||||||
test-sigchain >actual
|
{ test-sigchain >actual; ret=$?; } &&
|
||||||
case "$?" in
|
case "$ret" in
|
||||||
143) true ;; # POSIX w/ SIGTERM=15
|
143) true ;; # POSIX w/ SIGTERM=15
|
||||||
271) true ;; # ksh w/ SIGTERM=15
|
271) true ;; # ksh w/ SIGTERM=15
|
||||||
3) true ;; # Windows
|
3) true ;; # Windows
|
||||||
|
|
|
@ -111,9 +111,9 @@ test_expect_success 'unknown color slots are ignored (branch)' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'unknown color slots are ignored (status)' '
|
test_expect_success 'unknown color slots are ignored (status)' '
|
||||||
git config color.status.nosuchslotwilleverbedefined white || exit
|
git config color.status.nosuchslotwilleverbedefined white &&
|
||||||
git status
|
{ git status; ret=$?; } &&
|
||||||
case $? in 0|1) : ok ;; *) false ;; esac
|
case $ret in 0|1) : ok ;; *) false ;; esac
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
|
@ -66,8 +66,10 @@ test_expect_success UNZIP 'zip archive of empty tree is empty' '
|
||||||
# handle the empty repo at all, making our later check of its exit code
|
# handle the empty repo at all, making our later check of its exit code
|
||||||
# a no-op). But we cannot do anything reasonable except skip the test
|
# a no-op). But we cannot do anything reasonable except skip the test
|
||||||
# on such platforms anyway, and this is the moral equivalent.
|
# on such platforms anyway, and this is the moral equivalent.
|
||||||
"$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
|
{
|
||||||
expect_code=$?
|
"$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
|
||||||
|
expect_code=$?
|
||||||
|
} &&
|
||||||
|
|
||||||
git archive --format=zip HEAD >empty.zip &&
|
git archive --format=zip HEAD >empty.zip &&
|
||||||
make_dir extract &&
|
make_dir extract &&
|
||||||
|
|
|
@ -103,8 +103,10 @@ test_expect_success 'confuses pattern as remote when no remote specified' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'die with non-2 for wrong repository even with --exit-code' '
|
test_expect_success 'die with non-2 for wrong repository even with --exit-code' '
|
||||||
git ls-remote --exit-code ./no-such-repository ;# not &&
|
{
|
||||||
status=$? &&
|
git ls-remote --exit-code ./no-such-repository
|
||||||
|
status=$?
|
||||||
|
} &&
|
||||||
test $status != 2 && test $status != 0
|
test $status != 2 && test $status != 0
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue