tests: fix broken &&-chains in compound statements

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 compound statements 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 74d2f5695dab4454097b2d1693f7206e8328724a
28 files changed +95 -89
t/perf/p0005-status.sh
+6 -6
@@ -24,17 +24,17 @@ test_perf_default_repo
24 test_expect_success "setup repo" '
25 if git rev-parse --verify refs/heads/p0006-ballast^{commit}
26 then
27 - echo Assuming synthetic repo from many-files.sh
28 - git branch br_base master
29 - git branch br_ballast p0006-ballast
30 - git config --local core.sparsecheckout 1
27 + echo Assuming synthetic repo from many-files.sh &&
28 + git branch br_base master &&
29 + git branch br_ballast p0006-ballast &&
30 + git config --local core.sparsecheckout 1 &&
31 cat >.git/info/sparse-checkout <<-EOF
32 /*
33 !ballast/*
34 EOF
35 else
36 - echo Assuming non-synthetic repo...
37 - git branch br_base $(git rev-list HEAD | tail -n 1)
36 + echo Assuming non-synthetic repo... &&
37 + git branch br_base $(git rev-list HEAD | tail -n 1) &&
38 git branch br_ballast HEAD
39 fi &&
40 git checkout -q br_ballast &&
t/perf/p0006-read-tree-checkout.sh
+10 -10
@@ -24,21 +24,21 @@ test_perf_default_repo
24 test_expect_success "setup repo" '
25 if git rev-parse --verify refs/heads/p0006-ballast^{commit}
26 then
27 - echo Assuming synthetic repo from many-files.sh
28 - git branch br_base master
29 - git branch br_ballast p0006-ballast^
30 - git branch br_ballast_alias p0006-ballast^
31 - git branch br_ballast_plus_1 p0006-ballast
32 - git config --local core.sparsecheckout 1
27 + echo Assuming synthetic repo from many-files.sh &&
28 + git branch br_base master &&
29 + git branch br_ballast p0006-ballast^ &&
30 + git branch br_ballast_alias p0006-ballast^ &&
31 + git branch br_ballast_plus_1 p0006-ballast &&
32 + git config --local core.sparsecheckout 1 &&
33 cat >.git/info/sparse-checkout <<-EOF
34 /*
35 !ballast/*
36 EOF
37 else
38 - echo Assuming non-synthetic repo...
39 - git branch br_base $(git rev-list HEAD | tail -n 1)
40 - git branch br_ballast HEAD^ || error "no ancestor commit from current head"
41 - git branch br_ballast_alias HEAD^
38 + echo Assuming non-synthetic repo... &&
39 + git branch br_base $(git rev-list HEAD | tail -n 1) &&
40 + git branch br_ballast HEAD^ || error "no ancestor commit from current head" &&
41 + git branch br_ballast_alias HEAD^ &&
42 git branch br_ballast_plus_1 HEAD
43 fi &&
44 git checkout -q br_ballast &&
t/perf/p0007-write-cache.sh
+2 -2
@@ -9,8 +9,8 @@ test_perf_default_repo
9 test_expect_success "setup repo" '
10 if git rev-parse --verify refs/heads/p0006-ballast^{commit}
11 then
12 - echo Assuming synthetic repo from many-files.sh
13 - git config --local core.sparsecheckout 1
12 + echo Assuming synthetic repo from many-files.sh &&
13 + git config --local core.sparsecheckout 1 &&
14 cat >.git/info/sparse-checkout <<-EOF
15 /*
16 !ballast/*
t/perf/p5302-pack-index.sh
+1 -1
@@ -21,7 +21,7 @@ test_expect_success 'set up thread-counting tests' '
21 threads= &&
22 while test $t -gt 0
23 do
24 - threads="$t $threads"
24 + threads="$t $threads" &&
25 t=$((t / 2))
26 done
27 '
t/perf/p5303-many-packs.sh
+4 -4
@@ -126,10 +126,10 @@ done
126 # Measure pack loading with 10,000 packs.
127 test_expect_success 'generate lots of packs' '
128 for i in $(test_seq 10000); do
129 - echo "blob"
130 - echo "data <<EOF"
131 - echo "blob $i"
132 - echo "EOF"
129 + echo "blob" &&
130 + echo "data <<EOF" &&
131 + echo "blob $i" &&
132 + echo "EOF" &&
133 echo "checkpoint"
134 done |
135 git -c fastimport.unpackLimit=0 fast-import
t/t1050-large.sh
+2 -2
@@ -54,7 +54,7 @@ test_expect_success 'add a large file or two' '
54 bad= count=0 idx= &&
55 for p in .git/objects/pack/pack-*.pack
56 do
57 - count=$(( $count + 1 ))
57 + count=$(( $count + 1 )) &&
58 if test_path_is_file "$p" &&
59 idx=${p%.pack}.idx && test_path_is_file "$idx"
60 then
@@ -78,7 +78,7 @@ test_expect_success 'add a large file or two' '
78 bad= count=0 &&
79 for p in .git/objects/pack/pack-*.pack
80 do
81 - count=$(( $count + 1 ))
81 + count=$(( $count + 1 )) &&
82 if test_path_is_file "$p" &&
83 idx=${p%.pack}.idx && test_path_is_file "$idx"
84 then
t/t1300-config.sh
+1 -1
@@ -717,7 +717,7 @@ test_expect_success bool '
717 rm -f result &&
718 for i in 1 2 3 4
719 do
720 - git config --bool --get bool.true$i >>result
720 + git config --bool --get bool.true$i >>result &&
721 git config --bool --get bool.false$i >>result
722 done &&
723 test_cmp expect result'
t/t1700-split-index.sh
+2 -2
@@ -48,10 +48,10 @@ test_expect_success 'enable split index' '
48 # NEEDSWORK: Stop hard-coding checksums.
49 if test "$indexversion" = "4"
50 then
51 - own=$(test_oid own_v4)
51 + own=$(test_oid own_v4) &&
52 base=$(test_oid base_v4)
53 else
54 - own=$(test_oid own_v3)
54 + own=$(test_oid own_v3) &&
55 base=$(test_oid base_v3)
56 fi &&
57
t/t2200-add-update.sh
+2 -2
@@ -150,8 +150,8 @@ test_expect_success 'add -u resolves unmerged paths' '
150 {
151 for path in path1 path2
152 do
153 - echo "100644 $one 1 $path"
154 - echo "100644 $two 2 $path"
153 + echo "100644 $one 1 $path" &&
154 + echo "100644 $two 2 $path" &&
155 echo "100644 $three 3 $path"
156 done
157 echo "100644 $one 1 path3"
t/t3070-wildmatch.sh
+1 -1
@@ -193,7 +193,7 @@ match() {
193 file=$(cat .git/expected_test_file) &&
194 if should_create_test_file "$file"
195 then
196 - dirs=${file%/*}
196 + dirs=${file%/*} &&
197 if test "$file" != "$dirs"
198 then
199 mkdir -p -- "$dirs" &&
t/t3700-add.sh
+2 -2
@@ -141,8 +141,8 @@ test_expect_success 'check correct prefix detection' '
141 test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries' '
142 for s in 1 2 3
143 do
144 - echo $s > stage$s
145 - echo "100755 $(git hash-object -w stage$s) $s file"
144 + echo $s > stage$s &&
145 + echo "100755 $(git hash-object -w stage$s) $s file" &&
146 echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink"
147 done | git update-index --index-info &&
148 git config core.filemode 0 &&
t/t4046-diff-unmerged.sh
+1 -1
@@ -18,7 +18,7 @@ test_expect_success setup '
18 for t in o x
19 do
20 path="$b$o$t" &&
21 - case "$path" in ooo) continue ;; esac
21 + case "$path" in ooo) continue ;; esac &&
22 paths="$paths$path " &&
23 p=" $path" &&
24 case "$b" in x) echo "$m1$p" ;; esac &&
t/t4123-apply-shrink.sh
+2 -2
@@ -45,8 +45,8 @@ test_expect_success 'apply should fail gracefully' '
45 echo Oops, should not have succeeded
46 false
47 else
48 - status=$?
49 - echo "Status was $status"
48 + status=$? &&
49 + echo "Status was $status" &&
50 if test -f .git/index.lock
51 then
52 echo Oops, should not have crashed
t/t4138-apply-ws-expansion.sh
+10 -10
@@ -29,7 +29,7 @@ test_expect_success setup '
29 x=1 &&
30 while test $x -lt $n
31 do
32 - printf "%63s%d\n" "" $x >>after
32 + printf "%63s%d\n" "" $x >>after &&
33 x=$(( $x + 1 ))
34 done &&
35 printf "\t%s\n" d e f >>after &&
@@ -40,7 +40,7 @@ test_expect_success setup '
40 x=1 &&
41 while test $x -lt $n
42 do
43 - printf "%63s%d\n" "" $x >>expect-2
43 + printf "%63s%d\n" "" $x >>expect-2 &&
44 x=$(( $x + 1 ))
45 done &&
46 printf "%64s\n" d e f >>expect-2 &&
@@ -52,7 +52,7 @@ test_expect_success setup '
52 x=0 &&
53 while test $x -lt $n
54 do
55 - printf "%63s%02d\n" "" $x >>after
55 + printf "%63s%02d\n" "" $x >>after &&
56 x=$(( $x + 1 ))
57 done &&
58 printf "\t%s\n" d e f >>after &&
@@ -63,7 +63,7 @@ test_expect_success setup '
63 x=0 &&
64 while test $x -lt $n
65 do
66 - printf "%63s%02d\n" "" $x >>expect-3
66 + printf "%63s%02d\n" "" $x >>expect-3 &&
67 x=$(( $x + 1 ))
68 done &&
69 printf "%64s\n" d e f >>expect-3 &&
@@ -73,15 +73,15 @@ test_expect_success setup '
73 x=0 &&
74 while test $x -lt 50
75 do
76 - printf "\t%02d\n" $x >>before
76 + printf "\t%02d\n" $x >>before &&
77 x=$(( $x + 1 ))
78 done &&
79 cat before >after &&
80 printf "%64s\n" a b c >>after &&
81 while test $x -lt 100
82 do
83 - printf "\t%02d\n" $x >>before
84 - printf "\t%02d\n" $x >>after
83 + printf "\t%02d\n" $x >>before &&
84 + printf "\t%02d\n" $x >>after &&
85 x=$(( $x + 1 ))
86 done &&
87 test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
@@ -90,15 +90,15 @@ test_expect_success setup '
90 x=0 &&
91 while test $x -lt 50
92 do
93 - printf "%63s%02d\n" "" $x >>test-4
93 + printf "%63s%02d\n" "" $x >>test-4 &&
94 x=$(( $x + 1 ))
95 done &&
96 cat test-4 >expect-4 &&
97 printf "%64s\n" a b c >>expect-4 &&
98 while test $x -lt 100
99 do
100 - printf "%63s%02d\n" "" $x >>test-4
101 - printf "%63s%02d\n" "" $x >>expect-4
100 + printf "%63s%02d\n" "" $x >>test-4 &&
101 + printf "%63s%02d\n" "" $x >>expect-4 &&
102 x=$(( $x + 1 ))
103 done &&
104
t/t5302-pack-index.sh
+1 -1
@@ -14,7 +14,7 @@ test_expect_success 'setup' '
14 i=1 &&
15 while test $i -le 100
16 do
17 - iii=$(printf "%03i" $i)
17 + iii=$(printf "%03i" $i) &&
18 test-tool genrandom "bar" 200 > wide_delta_$iii &&
19 test-tool genrandom "baz $iii" 50 >> wide_delta_$iii &&
20 test-tool genrandom "foo"$i 100 > deep_delta_$iii &&
t/t5317-pack-objects-filter-objects.sh
+10 -10
@@ -16,8 +16,8 @@ test_expect_success 'setup r1' '
16 git init r1 &&
17 for n in 1 2 3 4 5
18 do
19 - echo "This is file: $n" > r1/file.$n
20 - git -C r1 add file.$n
19 + echo "This is file: $n" > r1/file.$n &&
20 + git -C r1 add file.$n &&
21 git -C r1 commit -m "$n"
22 done
23 '
@@ -116,8 +116,8 @@ test_expect_success 'setup r2' '
116 git init r2 &&
117 for n in 1000 10000
118 do
119 - printf "%"$n"s" X > r2/large.$n
120 - git -C r2 add large.$n
119 + printf "%"$n"s" X > r2/large.$n &&
120 + git -C r2 add large.$n &&
121 git -C r2 commit -m "$n"
122 done
123 '
@@ -278,9 +278,9 @@ test_expect_success 'setup r3' '
278 mkdir r3/dir1 &&
279 for n in sparse1 sparse2
280 do
281 - echo "This is file: $n" > r3/$n
282 - git -C r3 add $n
283 - echo "This is file: dir1/$n" > r3/dir1/$n
281 + echo "This is file: $n" > r3/$n &&
282 + git -C r3 add $n &&
283 + echo "This is file: dir1/$n" > r3/dir1/$n &&
284 git -C r3 add dir1/$n
285 done &&
286 git -C r3 commit -m "sparse" &&
@@ -331,9 +331,9 @@ test_expect_success 'setup r4' '
331 mkdir r4/dir1 &&
332 for n in sparse1 sparse2
333 do
334 - echo "This is file: $n" > r4/$n
335 - git -C r4 add $n
336 - echo "This is file: dir1/$n" > r4/dir1/$n
334 + echo "This is file: $n" > r4/$n &&
335 + git -C r4 add $n &&
336 + echo "This is file: dir1/$n" > r4/dir1/$n &&
337 git -C r4 add dir1/$n
338 done &&
339 echo dir1/ >r4/pattern &&
t/t5571-pre-push-hook.sh
+1 -1
@@ -117,7 +117,7 @@ test_expect_success 'set up many-ref tests' '
117 nr=1000
118 while test $nr -lt 2000
119 do
120 - nr=$(( $nr + 1 ))
120 + nr=$(( $nr + 1 )) &&
121 echo "create refs/heads/b/$nr $COMMIT3"
122 done
123 } | git update-ref --stdin
t/t5616-partial-clone.sh
+9 -9
@@ -16,9 +16,9 @@ test_expect_success 'setup normal src repo' '
16 git init src &&
17 for n in 1 2 3 4
18 do
19 - echo "This is file: $n" > src/file.$n.txt
20 - git -C src add file.$n.txt
21 - git -C src commit -m "file $n"
19 + echo "This is file: $n" > src/file.$n.txt &&
20 + git -C src add file.$n.txt &&
21 + git -C src commit -m "file $n" &&
22 git -C src ls-files -s file.$n.txt >>temp
23 done &&
24 awk -f print_2.awk <temp | sort >expect_1.oids &&
@@ -72,8 +72,8 @@ test_expect_success 'push new commits to server' '
72 git -C src remote add srv "file://$(pwd)/srv.bare" &&
73 for x in a b c d e
74 do
75 - echo "Mod file.1.txt $x" >>src/file.1.txt
76 - git -C src add file.1.txt
75 + echo "Mod file.1.txt $x" >>src/file.1.txt &&
76 + git -C src add file.1.txt &&
77 git -C src commit -m "mod $x"
78 done &&
79 git -C src blame main -- file.1.txt >expect.blame &&
@@ -114,8 +114,8 @@ test_expect_success 'verify blame causes dynamic object fetch' '
114 test_expect_success 'push new commits to server for file.2.txt' '
115 for x in a b c d e f
116 do
117 - echo "Mod file.2.txt $x" >>src/file.2.txt
118 - git -C src add file.2.txt
117 + echo "Mod file.2.txt $x" >>src/file.2.txt &&
118 + git -C src add file.2.txt &&
119 git -C src commit -m "mod $x"
120 done &&
121 git -C src push -u srv main
@@ -135,8 +135,8 @@ test_expect_success 'override inherited filter-spec using --no-filter' '
135 test_expect_success 'push new commits to server for file.3.txt' '
136 for x in a b c d e f
137 do
138 - echo "Mod file.3.txt $x" >>src/file.3.txt
139 - git -C src add file.3.txt
138 + echo "Mod file.3.txt $x" >>src/file.3.txt &&
139 + git -C src add file.3.txt &&
140 git -C src commit -m "mod $x"
141 done &&
142 git -C src push -u srv main
t/t6005-rev-list-count.sh
+4 -4
@@ -5,10 +5,10 @@ test_description='git rev-list --max-count and --skip test'
5 . ./test-lib.sh
6
7 test_expect_success 'setup' '
8 - for n in 1 2 3 4 5 ; do \
9 - echo $n > a ; \
10 - git add a ; \
11 - git commit -m "$n" ; \
8 + for n in 1 2 3 4 5 ; do
9 + echo $n > a &&
10 + git add a &&
11 + git commit -m "$n"
12 done
13 '
14
t/t6009-rev-list-parent.sh
+1 -1
@@ -142,7 +142,7 @@ test_expect_success 'ancestors with the same commit time' '
142
143 test_tick_keep=$test_tick &&
144 for i in 1 2 3 4 5 6 7 8; do
145 - test_tick=$test_tick_keep
145 + test_tick=$test_tick_keep &&
146 test_commit t$i
147 done &&
148 git rev-list t1^! --not t$i >result &&
t/t6112-rev-list-filters-objects.sh
+7 -7
@@ -16,8 +16,8 @@ test_expect_success 'setup r1' '
16 git init r1 &&
17 for n in 1 2 3 4 5
18 do
19 - echo "This is file: $n" > r1/file.$n
20 - git -C r1 add file.$n
19 + echo "This is file: $n" > r1/file.$n &&
20 + git -C r1 add file.$n &&
21 git -C r1 commit -m "$n"
22 done
23 '
@@ -73,8 +73,8 @@ test_expect_success 'setup r2' '
73 git init r2 &&
74 for n in 1000 10000
75 do
76 - printf "%"$n"s" X > r2/large.$n
77 - git -C r2 add large.$n
76 + printf "%"$n"s" X > r2/large.$n &&
77 + git -C r2 add large.$n &&
78 git -C r2 commit -m "$n"
79 done
80 '
@@ -245,9 +245,9 @@ test_expect_success 'setup r3' '
245 mkdir r3/dir1 &&
246 for n in sparse1 sparse2
247 do
248 - echo "This is file: $n" > r3/$n
249 - git -C r3 add $n
250 - echo "This is file: dir1/$n" > r3/dir1/$n
248 + echo "This is file: $n" > r3/$n &&
249 + git -C r3 add $n &&
250 + echo "This is file: dir1/$n" > r3/dir1/$n &&
251 git -C r3 add dir1/$n
252 done &&
253 git -C r3 commit -m "sparse" &&
t/t6120-describe.sh
+5 -2
@@ -390,8 +390,11 @@ test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' '
390 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
391 data <<EOF
392 commit #$i
393 -EOF"
394 - test $i = 1 && echo "from refs/heads/main^0"
393 +EOF" &&
394 + if test $i = 1
395 + then
396 + echo "from refs/heads/main^0"
397 + fi &&
398 i=$(($i + 1))
399 done | git fast-import &&
400 git checkout main &&
t/t6407-merge-binary.sh
+2 -2
@@ -47,7 +47,7 @@ test_expect_success resolve '
47 echo Oops, should not have succeeded
48 false
49 else
50 - git ls-files -s >current
50 + git ls-files -s >current &&
51 test_cmp expect current
52 fi
53 '
@@ -62,7 +62,7 @@ test_expect_success recursive '
62 echo Oops, should not have succeeded
63 false
64 else
65 - git ls-files -s >current
65 + git ls-files -s >current &&
66 test_cmp expect current
67 fi
68 '
t/t6412-merge-large-rename.sh
+1 -1
@@ -47,7 +47,7 @@ test_rename() {
47 git commit -a -m change=$n &&
48 git checkout -b test$n HEAD^ &&
49 for i in $(count $n); do
50 - git rm $i
50 + git rm $i &&
51 make_text $i initial changed >$i.moved
52 done &&
53 git add . &&
t/t7004-tag.sh
+5 -2
@@ -1976,8 +1976,11 @@ test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a de
1976 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1977 data <<EOF
1978 commit #$i
1979 -EOF"
1980 - test $i = 1 && echo "from refs/heads/main^0"
1979 +EOF" &&
1980 + if test $i = 1
1981 + then
1982 + echo "from refs/heads/main^0"
1983 + fi &&
1984 i=$(($i + 1))
1985 done | git fast-import &&
1986 git checkout main &&
t/t7519-status-fsmonitor.sh
+1 -1
@@ -248,7 +248,7 @@ do
248 git config core.preloadIndex $preload_val &&
249 if test $preload_val = true
250 then
251 - GIT_TEST_PRELOAD_INDEX=$preload_val; export GIT_TEST_PRELOAD_INDEX
251 + GIT_TEST_PRELOAD_INDEX=$preload_val && export GIT_TEST_PRELOAD_INDEX
252 else
253 sane_unset GIT_TEST_PRELOAD_INDEX
254 fi
t/t7602-merge-octopus-many.sh
+1 -1
@@ -29,7 +29,7 @@ test_expect_success 'merge c1 with c2, c3, c4, ... c29' '
29 refs="" &&
30 while test $i -le 30
31 do
32 - refs="$refs c$i"
32 + refs="$refs c$i" &&
33 i=$(expr $i + 1)
34 done &&
35 git merge $refs &&
t/t9130-git-svn-authors-file.sh
+1 -1
@@ -59,7 +59,7 @@ test_expect_success 'authors-file against globs' '
59 git svn clone --authors-file=svn-authors -s "$svnrepo"/aa aa-work &&
60 for i in bb ee cc
61 do
62 - branch="aa/branches/$i"
62 + branch="aa/branches/$i" &&
63 svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch"
64 done
65 '