]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: fix broken &&-chains in `$(...)` command substitutions
authorEric Sunshine <sunshine@sunshineco.com>
Thu, 9 Dec 2021 05:11:07 +0000 (00:11 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 18:29:48 +0000 (10:29 -0800)
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>
contrib/subtree/t/t7900-subtree.sh
t/t0005-signals.sh
t/t0060-path-utils.sh
t/t1006-cat-file.sh
t/t3600-rm.sh
t/t7010-setup.sh

index 4153b6532195142c19f83c09ab2991d0abc821ad..1c1f76f04aaed3f15fec9d750762f46ee86c4cab 100755 (executable)
@@ -1445,7 +1445,7 @@ test_expect_success 'subtree descendant check' '
        ) &&
        test_create_commit "$test_count" folder_subtree/0 &&
        test_create_commit "$test_count" folder_subtree/b &&
-       cherry=$(cd "$test_count"; git rev-parse HEAD) &&
+       cherry=$(cd "$test_count" && git rev-parse HEAD) &&
        (
                cd "$test_count" &&
                git checkout branch
index a5ec6a0315ca09893e5c2b7403e91f2a0be0109c..eba75a2490ce7e0918e6a981d42ec8f5d9fd9b2d 100755 (executable)
@@ -48,7 +48,7 @@ test_expect_success !MINGW 'a constipated git dies with SIGPIPE' '
 '
 
 test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' '
-       OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) &&
+       OUT=$( ((trap "" PIPE && large_git; echo $? 1>&3) | :) 3>&1 ) &&
        test_match_signal 13 "$OUT"
 '
 
index 34d1061f321fb406a5e3d6058860da957307dfab..71a5d370cc7bc7d369b7e3099c064bc8cb114d7d 100755 (executable)
@@ -216,7 +216,7 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
        mkdir second &&
        ln -s ../first second/other &&
        mkdir third &&
-       dir="$(cd .git; pwd -P)" &&
+       dir="$(cd .git && pwd -P)" &&
        dir2=third/../second/other/.git &&
        test "$dir" = "$(test-tool path-utils real_path $dir2)" &&
        file="$dir"/index &&
@@ -224,7 +224,7 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
        basename=blub &&
        test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" &&
        ln -s ../first/file .git/syml &&
-       sym="$(cd first; pwd -P)"/file &&
+       sym="$(cd first && pwd -P)"/file &&
        test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")"
 '
 
index 658628375c85b17e44aa501c7624daddff4053f6..67a3f64c2d68008edb3695234b6d1e6c43124c0a 100755 (executable)
@@ -211,14 +211,14 @@ done
 test_expect_success "--batch-check for a non-existent named object" '
     test "foobar42 missing
 foobar84 missing" = \
-    "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
+    "$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)"
 '
 
 test_expect_success "--batch-check for a non-existent hash" '
     test "0000000000000000000000000000000000000042 missing
 0000000000000000000000000000000000000084 missing" = \
-    "$( ( echo 0000000000000000000000000000000000000042;
-        echo_without_newline 0000000000000000000000000000000000000084; ) |
+    "$( ( echo 0000000000000000000000000000000000000042 &&
+        echo_without_newline 0000000000000000000000000000000000000084 ) |
        git cat-file --batch-check)"
 '
 
@@ -226,8 +226,8 @@ test_expect_success "--batch for an existent and a non-existent hash" '
     test "$tag_sha1 tag $tag_size
 $tag_content
 0000000000000000000000000000000000000000 missing" = \
-    "$( ( echo $tag_sha1;
-        echo_without_newline 0000000000000000000000000000000000000000; ) |
+    "$( ( echo $tag_sha1 &&
+        echo_without_newline 0000000000000000000000000000000000000000 ) |
        git cat-file --batch)"
 '
 
index bb9ef35dac082e396d5cbcbdc83bc5394fb95a7c..ed3952eb98bafb92581bacdfc453d3dfba3ca41e 100755 (executable)
@@ -265,7 +265,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft (induce S
 
 test_expect_success !MINGW 'choking "git rm" should not let it die with cruft (induce and check SIGPIPE)' '
        choke_git_rm_setup &&
-       OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
+       OUT=$( ((trap "" PIPE && git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
        test_match_signal 13 "$OUT" &&
        test_path_is_missing .git/index.lock
 '
index 0335a9a158ab507b2e37e4d7642a69ba4344c0ad..520f96d09fb71778704119929012a40aa7c0072a 100755 (executable)
@@ -137,7 +137,7 @@ test_expect_success 'setup deeper work tree' '
 
 test_expect_success 'add a directory outside the work tree' '(
        cd tester &&
-       d1="$(cd .. ; pwd)" &&
+       d1="$(cd .. && pwd)" &&
        test_must_fail git add "$d1"
 )'