Skip to content

Commit d0fd993

Browse files
sunshinecogitster
authored andcommitted
t5000-t5999: detect and signal failure within loop
Failures within `for` and `while` loops can go unnoticed if not detected and signaled manually since the loop itself does not abort when a contained command fails, nor will a failure necessarily be detected when the loop finishes since the loop returns the exit code of the last command it ran on the final iteration, which may not be the command which failed. Therefore, detect and signal failures manually within loops using the idiom `|| return 1` (or `|| exit 1` within subshells). Signed-off-by: Eric Sunshine <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbe1d9d commit d0fd993

20 files changed

+50
-50
lines changed

t/t5000-tar-tree.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ check_tar() {
7777
path=$(get_pax_header $header path) &&
7878
if test -n "$path"
7979
then
80-
mv "$data" "$path"
80+
mv "$data" "$path" || exit 1
8181
fi
8282
fi
8383
done
@@ -133,7 +133,7 @@ test_expect_success 'populate workdir' '
133133
for depth in 1 2 3 4 5
134134
do
135135
mkdir $p &&
136-
cd $p
136+
cd $p || exit 1
137137
done &&
138138
echo text >file_with_long_path
139139
) &&

t/t5003-archive-zip.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ test_expect_success \
106106
printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
107107
printf "A not substituted O" >a/substfile2 &&
108108
(p=long_path_to_a_file && cd a &&
109-
for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
109+
for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done &&
110110
echo text >file_with_long_path)
111111
'
112112

t/t5004-archive-corner-cases.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
131131
do
132132
for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f
133133
do
134-
: >00/$a$b
134+
: >00/$a$b || return 1
135135
done
136136
done &&
137137
git add 00 &&
@@ -143,7 +143,7 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
143143
do
144144
for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f
145145
do
146-
echo "040000 tree $subtree $c$d"
146+
echo "040000 tree $subtree $c$d" || return 1
147147
done
148148
done >tree &&
149149
tree=$(git mktree <tree) &&
@@ -171,7 +171,7 @@ test_expect_success EXPENSIVE,UNZIP,UNZIP_ZIP64_SUPPORT \
171171
# create tree containing 65500 entries of that blob
172172
for i in $(test_seq 1 65500)
173173
do
174-
echo "100644 blob $blob $i"
174+
echo "100644 blob $blob $i" || return 1
175175
done >tree &&
176176
tree=$(git mktree <tree) &&
177177

t/t5100-mailinfo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ test_expect_success 'mailinfo unescapes with --mboxrd' '
122122
do
123123
git mailinfo mboxrd/msg mboxrd/patch \
124124
<mboxrd/$i >mboxrd/out &&
125-
test_cmp "$DATA/${i}mboxrd" mboxrd/msg
125+
test_cmp "$DATA/${i}mboxrd" mboxrd/msg || return 1
126126
done &&
127127
sp=" " &&
128128
echo "From " >expect &&

t/t5300-pack-object.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ test_expect_success 'unpacking with --strict' '
347347
for i in 0 1 2 3 4 5 6 7 8 9
348348
do
349349
o=$(echo $j$i | git hash-object -w --stdin) &&
350-
echo "100644 $o 0 $j$i"
350+
echo "100644 $o 0 $j$i" || return 1
351351
done
352352
done >LIST &&
353353
rm -f .git/index &&
@@ -390,7 +390,7 @@ test_expect_success 'index-pack with --strict' '
390390
for i in 0 1 2 3 4 5 6 7 8 9
391391
do
392392
o=$(echo $j$i | git hash-object -w --stdin) &&
393-
echo "100644 $o 0 $j$i"
393+
echo "100644 $o 0 $j$i" || return 1
394394
done
395395
done >LIST &&
396396
rm -f .git/index &&
@@ -586,7 +586,7 @@ test_expect_success 'setup for --stdin-packs tests' '
586586
for id in A B C
587587
do
588588
git pack-objects .git/objects/pack/pack-$id \
589-
--incremental --revs <<-EOF
589+
--incremental --revs <<-EOF || exit 1
590590
refs/tags/$id
591591
EOF
592592
done &&

t/t5307-pack-missing-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_expect_success setup '
1111
git add "file$i" &&
1212
test_tick &&
1313
git commit -m "$i" &&
14-
git tag "tag$i"
14+
git tag "tag$i" || return 1
1515
done &&
1616
obj=$(git rev-parse --verify tag3) &&
1717
fanout=$(expr "$obj" : "\(..\)") &&

t/t5310-pack-bitmaps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ test_expect_success 'pack reuse respects --honor-pack-keep' '
230230
test_when_finished "rm -f .git/objects/pack/*.keep" &&
231231
for i in .git/objects/pack/*.pack
232232
do
233-
>${i%.pack}.keep
233+
>${i%.pack}.keep || return 1
234234
done &&
235235
reusable_pack --honor-pack-keep >empty.pack &&
236236
git index-pack empty.pack &&

t/t5317-pack-objects-filter-objects.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test_expect_success 'setup r1' '
1818
do
1919
echo "This is file: $n" > r1/file.$n &&
2020
git -C r1 add file.$n &&
21-
git -C r1 commit -m "$n"
21+
git -C r1 commit -m "$n" || return 1
2222
done
2323
'
2424

@@ -118,7 +118,7 @@ test_expect_success 'setup r2' '
118118
do
119119
printf "%"$n"s" X > r2/large.$n &&
120120
git -C r2 add large.$n &&
121-
git -C r2 commit -m "$n"
121+
git -C r2 commit -m "$n" || return 1
122122
done
123123
'
124124

@@ -281,7 +281,7 @@ test_expect_success 'setup r3' '
281281
echo "This is file: $n" > r3/$n &&
282282
git -C r3 add $n &&
283283
echo "This is file: dir1/$n" > r3/dir1/$n &&
284-
git -C r3 add dir1/$n
284+
git -C r3 add dir1/$n || return 1
285285
done &&
286286
git -C r3 commit -m "sparse" &&
287287
echo dir1/ >pattern1 &&
@@ -334,7 +334,7 @@ test_expect_success 'setup r4' '
334334
echo "This is file: $n" > r4/$n &&
335335
git -C r4 add $n &&
336336
echo "This is file: dir1/$n" > r4/dir1/$n &&
337-
git -C r4 add dir1/$n
337+
git -C r4 add dir1/$n || return 1
338338
done &&
339339
echo dir1/ >r4/pattern &&
340340
git -C r4 add pattern &&
@@ -409,7 +409,7 @@ test_expect_success 'setup r1 - delete loose blobs' '
409409
410410
for id in `cat expected | sed "s|..|&/|"`
411411
do
412-
rm r1/.git/objects/$id
412+
rm r1/.git/objects/$id || return 1
413413
done
414414
'
415415

t/t5318-commit-graph.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test_expect_success 'create commits and repack' '
6464
for i in $(test_seq 3)
6565
do
6666
test_commit $i &&
67-
git branch commits/$i
67+
git branch commits/$i || return 1
6868
done &&
6969
git repack
7070
'
@@ -147,13 +147,13 @@ test_expect_success 'Add more commits' '
147147
for i in $(test_seq 4 5)
148148
do
149149
test_commit $i &&
150-
git branch commits/$i
150+
git branch commits/$i || return 1
151151
done &&
152152
git reset --hard commits/2 &&
153153
for i in $(test_seq 6 7)
154154
do
155155
test_commit $i &&
156-
git branch commits/$i
156+
git branch commits/$i || return 1
157157
done &&
158158
git reset --hard commits/2 &&
159159
git merge commits/4 &&

t/t5319-multi-pack-index.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test_expect_success 'create objects' '
9393
test_commit initial &&
9494
for i in $(test_seq 1 5)
9595
do
96-
generate_objects $i
96+
generate_objects $i || return 1
9797
done &&
9898
commit_and_list_objects
9999
'
@@ -155,7 +155,7 @@ test_expect_success 'corrupt idx reports errors' '
155155
test_expect_success 'add more objects' '
156156
for i in $(test_seq 6 10)
157157
do
158-
generate_objects $i
158+
generate_objects $i || return 1
159159
done &&
160160
commit_and_list_objects
161161
'
@@ -203,7 +203,7 @@ test_expect_success 'add more packs' '
203203
do
204204
generate_objects $j &&
205205
commit_and_list_objects &&
206-
git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list
206+
git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list || return 1
207207
done
208208
'
209209

@@ -594,7 +594,7 @@ test_expect_success 'force some 64-bit offsets with pack-objects' '
594594
mkdir objects64/pack &&
595595
for i in $(test_seq 1 11)
596596
do
597-
generate_objects 11
597+
generate_objects 11 || return 1
598598
done &&
599599
commit_and_list_objects &&
600600
pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
@@ -638,7 +638,7 @@ test_expect_success 'setup expire tests' '
638638
git update-index --add large_file.txt &&
639639
for i in $(test_seq 1 20)
640640
do
641-
test_commit $i
641+
test_commit $i || exit 1
642642
done &&
643643
git branch A HEAD &&
644644
git branch B HEAD~8 &&

0 commit comments

Comments
 (0)