tests: fix broken &&-chains in `{...}` groups
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 `{...}` groups 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
7abcbcb7ea4303adffd169d5367ce70904e79bf5
19 files changed
+53
-50
t/t0021-conversion.sh
+4
-4
@@ -76,13 +76,13 @@ test_expect_success setup '
76
git config filter.rot13.clean ./rot13.sh &&
77
78
{
79
- echo "*.t filter=rot13"
79
+ echo "*.t filter=rot13" &&
80
echo "*.i ident"
81
} >.gitattributes &&
82
83
{
84
- echo a b c d e f g h i j k l m
85
- echo n o p q r s t u v w x y z
84
+ echo a b c d e f g h i j k l m &&
85
+ echo n o p q r s t u v w x y z &&
86
echo '\''$Id$'\''
87
} >test &&
88
cat test >test.t &&
@@ -159,7 +159,7 @@ test_expect_success expanded_in_repo '
159
printf "\$Id: NoTerminatingSymbolAtEOF"
160
} >expected-output-crlf &&
161
{
162
- echo "expanded-keywords ident"
162
+ echo "expanded-keywords ident" &&
163
echo "expanded-keywords-crlf ident text eol=crlf"
164
} >>.gitattributes &&
165
t/t0069-oidtree.sh
+6
-6
@@ -28,7 +28,7 @@ test_expect_success 'oidtree insert and contains' '
28
EOF
29
{
30
echoid insert 444 1 2 3 4 5 a b c d e &&
31
- echoid contains 44 441 440 444 4440 4444
31
+ echoid contains 44 441 440 444 4440 4444 &&
32
echo clear
33
} | test-tool oidtree >actual &&
34
test_cmp expect actual
@@ -37,11 +37,11 @@ test_expect_success 'oidtree insert and contains' '
37
test_expect_success 'oidtree each' '
38
echoid "" 123 321 321 >expect &&
39
{
40
- echoid insert f 9 8 123 321 a b c d e
41
- echo each 12300
42
- echo each 3211
43
- echo each 3210
44
- echo each 32100
40
+ echoid insert f 9 8 123 321 a b c d e &&
41
+ echo each 12300 &&
42
+ echo each 3211 &&
43
+ echo each 3210 &&
44
+ echo each 32100 &&
45
echo clear
46
} | test-tool oidtree >actual &&
47
test_cmp expect actual
t/t1006-cat-file.sh
+1
-1
@@ -283,7 +283,7 @@ test_expect_success "--batch-check with multiple sha1s gives correct format" '
283
284
test_expect_success 'setup blobs which are likely to delta' '
285
test-tool genrandom foo 10240 >foo &&
286
- { cat foo; echo plus; } >foo-plus &&
286
+ { cat foo && echo plus; } >foo-plus &&
287
git add foo foo-plus &&
288
git commit -m foo &&
289
cat >blobs <<-\EOF
t/t1300-config.sh
+1
-1
@@ -901,7 +901,7 @@ test_expect_success 'get --expiry-date' '
901
EOF
902
: "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
903
{
904
- echo "$rel_out $(git config --expiry-date date.valid1)"
904
+ echo "$rel_out $(git config --expiry-date date.valid1)" &&
905
git config --expiry-date date.valid2 &&
906
git config --expiry-date date.valid3 &&
907
git config --expiry-date date.valid4 &&
t/t1403-show-ref.sh
+4
-4
@@ -78,7 +78,7 @@ test_expect_success 'show-ref --verify -q' '
78
test_expect_success 'show-ref -d' '
79
{
80
echo $(git rev-parse refs/tags/A) refs/tags/A &&
81
- echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}"
81
+ echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}" &&
82
echo $(git rev-parse refs/tags/C) refs/tags/C
83
} >expect &&
84
git show-ref -d A C >actual &&
@@ -148,7 +148,7 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' '
148
149
{
150
echo $(git rev-parse HEAD) HEAD &&
151
- echo $(git rev-parse refs/heads/B) refs/heads/B
151
+ echo $(git rev-parse refs/heads/B) refs/heads/B &&
152
echo $(git rev-parse refs/tags/B) refs/tags/B
153
} >expect &&
154
git show-ref --head B >actual &&
@@ -156,8 +156,8 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' '
156
157
{
158
echo $(git rev-parse HEAD) HEAD &&
159
- echo $(git rev-parse refs/heads/B) refs/heads/B
160
- echo $(git rev-parse refs/tags/B) refs/tags/B
159
+ echo $(git rev-parse refs/heads/B) refs/heads/B &&
160
+ echo $(git rev-parse refs/tags/B) refs/tags/B &&
161
echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}"
162
} >expect &&
163
git show-ref --head -d B >actual &&
t/t2200-add-update.sh
+6
-6
@@ -153,10 +153,10 @@ test_expect_success 'add -u resolves unmerged paths' '
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"
158
- echo "100644 $one 1 path4"
159
- echo "100644 $one 3 path5"
156
+ done &&
157
+ echo "100644 $one 1 path3" &&
158
+ echo "100644 $one 1 path4" &&
159
+ echo "100644 $one 3 path5" &&
160
echo "100644 $one 3 path6"
161
} |
162
git update-index --index-info &&
@@ -173,8 +173,8 @@ test_expect_success 'add -u resolves unmerged paths' '
173
git add -u &&
174
git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
175
{
176
- echo "100644 $three 0 path1"
177
- echo "100644 $two 0 path3"
176
+ echo "100644 $three 0 path1" &&
177
+ echo "100644 $two 0 path3" &&
178
echo "100644 $two 0 path5"
179
} >expect &&
180
test_cmp expect actual
t/t2201-add-update-typechange.sh
+5
-5
@@ -97,17 +97,17 @@ test_expect_success modify '
97
"
98
} >expect &&
99
{
100
- cat expect
101
- echo ":100644 160000 $_empty $ZERO_OID T yonk"
100
+ cat expect &&
101
+ echo ":100644 160000 $_empty $ZERO_OID T yonk" &&
102
echo ":100644 000000 $_empty $ZERO_OID D zifmia"
103
} >expect-files &&
104
{
105
- cat expect
105
+ cat expect &&
106
echo ":000000 160000 $ZERO_OID $ZERO_OID A yonk"
107
} >expect-index &&
108
{
109
- echo "100644 $_empty 0 nitfol"
110
- echo "160000 $yomin 0 yomin"
109
+ echo "100644 $_empty 0 nitfol" &&
110
+ echo "160000 $yomin 0 yomin" &&
111
echo "160000 $yonk 0 yonk"
112
} >expect-final
113
'
t/t4023-diff-rename-typechange.sh
+3
-3
@@ -55,7 +55,7 @@ test_expect_success 'cross renames to be detected for regular files' '
55
56
git diff-tree five six -r --name-status -B -M | sort >actual &&
57
{
58
- echo "R100 foo bar"
58
+ echo "R100 foo bar" &&
59
echo "R100 bar foo"
60
} | sort >expect &&
61
test_cmp expect actual
@@ -66,7 +66,7 @@ test_expect_success 'cross renames to be detected for typechange' '
66
67
git diff-tree one two -r --name-status -B -M | sort >actual &&
68
{
69
- echo "R100 foo bar"
69
+ echo "R100 foo bar" &&
70
echo "R100 bar foo"
71
} | sort >expect &&
72
test_cmp expect actual
@@ -78,7 +78,7 @@ test_expect_success 'moves and renames' '
78
git diff-tree three four -r --name-status -B -M | sort >actual &&
79
{
80
# see -B -M (#6) in t4008
81
- echo "C100 foo bar"
81
+ echo "C100 foo bar" &&
82
echo "T100 foo"
83
} | sort >expect &&
84
test_cmp expect actual
t/t4124-apply-ws-rule.sh
+1
-1
@@ -233,7 +233,7 @@ test_expect_success 'blank at EOF with --whitespace=fix (1)' '
233
test_write_lines a b c >one &&
234
git add one &&
235
test_write_lines a b c >expect &&
236
- { cat expect; echo; } >one &&
236
+ { cat expect && echo; } >one &&
237
git diff -- one >patch &&
238
239
git checkout one &&
t/t4150-am.sh
+1
-1
@@ -116,7 +116,7 @@ test_expect_success setup '
116
git format-patch --stdout first | sed -e "1d"
117
} | append_cr >patch1-crlf.eml &&
118
{
119
- printf "%255s\\n" ""
119
+ printf "%255s\\n" "" &&
120
echo "X-Fake-Field: Line One" &&
121
echo "X-Fake-Field: Line Two" &&
122
echo "X-Fake-Field: Line Three" &&
t/t4212-log-corrupt.sh
+4
-4
@@ -20,10 +20,10 @@ test_expect_success 'fsck notices broken commit' '
20
21
test_expect_success 'git log with broken author email' '
22
{
23
- echo commit $(cat broken_email.hash)
24
- echo "Author: A U Thor <author@example.com>"
25
- echo "Date: Thu Apr 7 15:13:13 2005 -0700"
26
- echo
23
+ echo commit $(cat broken_email.hash) &&
24
+ echo "Author: A U Thor <author@example.com>" &&
25
+ echo "Date: Thu Apr 7 15:13:13 2005 -0700" &&
26
+ echo &&
27
echo " foo"
28
} >expect.out &&
29
t/t5316-pack-delta-depth.sh
+5
-2
@@ -57,8 +57,11 @@ test_expect_success 'create series of packs' '
57
git commit -m $i &&
58
cur=$(git rev-parse HEAD^{tree}) &&
59
{
60
- test -n "$prev" && echo "-$prev"
61
- echo $cur
60
+ if test -n "$prev"
61
+ then
62
+ echo "-$prev"
63
+ fi &&
64
+ echo $cur &&
65
echo "$(git rev-parse :file) file"
66
} | git pack-objects --stdout >tmp &&
67
git index-pack --stdin --fix-thin <tmp || return 1
t/t5510-fetch.sh
+1
-1
@@ -71,7 +71,7 @@ test_expect_success "fetch test for-merge" '
71
main_in_two=$(cd ../two && git rev-parse main) &&
72
one_in_two=$(cd ../two && git rev-parse one) &&
73
{
74
- echo "$one_in_two "
74
+ echo "$one_in_two " &&
75
echo "$main_in_two not-for-merge"
76
} >expected &&
77
cut -f -2 .git/FETCH_HEAD >actual &&
t/t5515-fetch-merge-logic.sh
+6
-6
@@ -191,17 +191,17 @@ do
191
cp "$expect_r" expect_r &&
192
convert_expected expect_r sed_script &&
193
{
194
- echo "# $cmd"
195
- set x $cmd; shift
196
- git symbolic-ref HEAD refs/heads/$1 ; shift
197
- rm -f .git/FETCH_HEAD
194
+ echo "# $cmd" &&
195
+ set x $cmd && shift &&
196
+ git symbolic-ref HEAD refs/heads/$1 && shift &&
197
+ rm -f .git/FETCH_HEAD &&
198
git for-each-ref \
199
refs/heads refs/remotes/rem refs/tags |
200
while read val type refname
201
do
202
git update-ref -d "$refname" "$val"
203
- done
204
- git fetch "$@" >/dev/null
203
+ done &&
204
+ git fetch "$@" >/dev/null &&
205
cat .git/FETCH_HEAD
206
} >"$actual_f" &&
207
git show-ref >"$actual_r" &&
t/t5562-http-backend-content-length.sh
+1
-1
@@ -63,7 +63,7 @@ test_expect_success 'setup' '
63
hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
64
{
65
printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \
66
- "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize_raw
66
+ "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize_raw &&
67
printf 0000 &&
68
echo "$hash_next" | git pack-objects --stdout
69
} >push_body &&
t/t5570-git-daemon.sh
+1
-1
@@ -194,7 +194,7 @@ test_expect_success 'hostname cannot break out of directory' '
194
195
test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
196
{
197
- printf "git-upload-pack /interp.git\n\0host=localhost" | packetize_raw
197
+ printf "git-upload-pack /interp.git\n\0host=localhost" | packetize_raw &&
198
printf "0000"
199
} >input &&
200
fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
t/t5571-pre-push-hook.sh
+1
-1
@@ -114,7 +114,7 @@ test_expect_success 'push to URL' '
114
115
test_expect_success 'set up many-ref tests' '
116
{
117
- nr=1000
117
+ nr=1000 &&
118
while test $nr -lt 2000
119
do
120
nr=$(( $nr + 1 )) &&
t/t7513-interpret-trailers.sh
+1
-1
@@ -156,7 +156,7 @@ test_expect_success 'with config option on the command line' '
156
Acked-by: Johan
157
Reviewed-by: Peff
158
EOF
159
- { echo; echo "Acked-by: Johan"; } |
159
+ { echo && echo "Acked-by: Johan"; } |
160
git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
161
--trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
162
test_cmp expected actual
t/t8002-blame.sh
+1
-1
@@ -97,7 +97,7 @@ test_expect_success 'set up abbrev tests' '
97
test_commit abbrev &&
98
sha1=$(git rev-parse --verify HEAD) &&
99
check_abbrev () {
100
- expect=$1; shift
100
+ expect=$1 && shift &&
101
echo $sha1 | cut -c 1-$expect >expect &&
102
git blame "$@" abbrev.t >actual &&
103
perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&