tests: fix broken &&-chains in `$(...)` command substitutions

The top-level &&-chain checker built into t/test-lib.sh causes tests to magically exit with code 117 if the &&-chain is broken. However, it has the shortcoming that the magic does not work within `{...}` groups, `(...)` subshells, `$(...)` substitutions, or within bodies of compound statements, such as `if`, `for`, `while`, `case`, etc. `chainlint.sed` partly fills in the gap by catching broken &&-chains in `(...)` subshells, but bugs can still lurk behind broken &&-chains in the other cases. Fix broken &&-chains in `$(...)` command substitutions in order to reduce the number of possible lurking bugs. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Dec 9, 2021 at 00:11 UTC c576868eaff8cc4c7fb5cf8b787756b16fde268b
6 files changed +11 -11
contrib/subtree/t/t7900-subtree.sh
+1 -1
@@ -1445,7 +1445,7 @@ test_expect_success 'subtree descendant check' '
1445 ) &&
1446 test_create_commit "$test_count" folder_subtree/0 &&
1447 test_create_commit "$test_count" folder_subtree/b &&
1448 - cherry=$(cd "$test_count"; git rev-parse HEAD) &&
1448 + cherry=$(cd "$test_count" && git rev-parse HEAD) &&
1449 (
1450 cd "$test_count" &&
1451 git checkout branch
t/t0005-signals.sh
+1 -1
@@ -48,7 +48,7 @@ test_expect_success !MINGW 'a constipated git dies with SIGPIPE' '
48 '
49
50 test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' '
51 - OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) &&
51 + OUT=$( ((trap "" PIPE && large_git; echo $? 1>&3) | :) 3>&1 ) &&
52 test_match_signal 13 "$OUT"
53 '
54
t/t0060-path-utils.sh
+2 -2
@@ -216,7 +216,7 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
216 mkdir second &&
217 ln -s ../first second/other &&
218 mkdir third &&
219 - dir="$(cd .git; pwd -P)" &&
219 + dir="$(cd .git && pwd -P)" &&
220 dir2=third/../second/other/.git &&
221 test "$dir" = "$(test-tool path-utils real_path $dir2)" &&
222 file="$dir"/index &&
@@ -224,7 +224,7 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
224 basename=blub &&
225 test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" &&
226 ln -s ../first/file .git/syml &&
227 - sym="$(cd first; pwd -P)"/file &&
227 + sym="$(cd first && pwd -P)"/file &&
228 test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")"
229 '
230
t/t1006-cat-file.sh
+5 -5
@@ -211,14 +211,14 @@ done
211 test_expect_success "--batch-check for a non-existent named object" '
212 test "foobar42 missing
213 foobar84 missing" = \
214 - "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
214 + "$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)"
215 '
216
217 test_expect_success "--batch-check for a non-existent hash" '
218 test "0000000000000000000000000000000000000042 missing
219 0000000000000000000000000000000000000084 missing" = \
220 - "$( ( echo 0000000000000000000000000000000000000042;
221 - echo_without_newline 0000000000000000000000000000000000000084; ) |
220 + "$( ( echo 0000000000000000000000000000000000000042 &&
221 + echo_without_newline 0000000000000000000000000000000000000084 ) |
222 git cat-file --batch-check)"
223 '
224
@@ -226,8 +226,8 @@ test_expect_success "--batch for an existent and a non-existent hash" '
226 test "$tag_sha1 tag $tag_size
227 $tag_content
228 0000000000000000000000000000000000000000 missing" = \
229 - "$( ( echo $tag_sha1;
230 - echo_without_newline 0000000000000000000000000000000000000000; ) |
229 + "$( ( echo $tag_sha1 &&
230 + echo_without_newline 0000000000000000000000000000000000000000 ) |
231 git cat-file --batch)"
232 '
233
t/t3600-rm.sh
+1 -1
@@ -265,7 +265,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft (induce S
265
266 test_expect_success !MINGW 'choking "git rm" should not let it die with cruft (induce and check SIGPIPE)' '
267 choke_git_rm_setup &&
268 - OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
268 + OUT=$( ((trap "" PIPE && git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
269 test_match_signal 13 "$OUT" &&
270 test_path_is_missing .git/index.lock
271 '
t/t7010-setup.sh
+1 -1
@@ -137,7 +137,7 @@ test_expect_success 'setup deeper work tree' '
137
138 test_expect_success 'add a directory outside the work tree' '(
139 cd tester &&
140 - d1="$(cd .. ; pwd)" &&
140 + d1="$(cd .. && pwd)" &&
141 test_must_fail git add "$d1"
142 )'
143