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>

Jeff King committed Mar 20, 2015 at 06:12 UTC 9ddc5ac97ecdd03ceda4b6e3ff20a7524a9f0f8d
4 files changed +13 -9
t/t0005-signals.sh
+2 -2
@@ -10,8 +10,8 @@ one
10 EOF
11
12 test_expect_success 'sigchain works' '
13 - test-sigchain >actual
14 - case "$?" in
13 + { test-sigchain >actual; ret=$?; } &&
14 + case "$ret" in
15 143) true ;; # POSIX w/ SIGTERM=15
16 271) true ;; # ksh w/ SIGTERM=15
17 3) true ;; # Windows
t/t4026-color.sh
+3 -3
@@ -111,9 +111,9 @@ test_expect_success 'unknown color slots are ignored (branch)' '
111 '
112
113 test_expect_success 'unknown color slots are ignored (status)' '
114 - git config color.status.nosuchslotwilleverbedefined white || exit
115 - git status
116 - case $? in 0|1) : ok ;; *) false ;; esac
114 + git config color.status.nosuchslotwilleverbedefined white &&
115 + { git status; ret=$?; } &&
116 + case $ret in 0|1) : ok ;; *) false ;; esac
117 '
118
119 test_done
t/t5004-archive-corner-cases.sh
+4 -2
@@ -66,8 +66,10 @@ test_expect_success UNZIP 'zip archive of empty tree is empty' '
66 # handle the empty repo at all, making our later check of its exit code
67 # a no-op). But we cannot do anything reasonable except skip the test
68 # on such platforms anyway, and this is the moral equivalent.
69 - "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
70 - expect_code=$?
69 + {
70 + "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
71 + expect_code=$?
72 + } &&
73
74 git archive --format=zip HEAD >empty.zip &&
75 make_dir extract &&
t/t5512-ls-remote.sh
+4 -2
@@ -103,8 +103,10 @@ test_expect_success 'confuses pattern as remote when no remote specified' '
103 '
104
105 test_expect_success 'die with non-2 for wrong repository even with --exit-code' '
106 - git ls-remote --exit-code ./no-such-repository ;# not &&
107 - status=$? &&
106 + {
107 + git ls-remote --exit-code ./no-such-repository
108 + status=$?
109 + } &&
110 test $status != 2 && test $status != 0
111 '
112