Skip to content

Commit 0c51d6b

Browse files
sunshinecogitster
authored andcommitted
t6000-t9999: 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 d0fd993 commit 0c51d6b

32 files changed

+65
-65
lines changed

contrib/mw-to-git/t/t9365-continuing-queries.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test_expect_success 'creating page w/ >500 revisions' '
1212
for i in $(test_seq 501)
1313
do
1414
echo "creating revision $i" &&
15-
wiki_editpage foo "revision $i<br/>" true
15+
wiki_editpage foo "revision $i<br/>" true || return 1
1616
done
1717
'
1818

t/annotate-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ test_expect_success 'blame huge graft' '
161161
GIT_AUTHOR_NAME=$i$j [email protected] \
162162
git commit -a -m "$i$j" &&
163163
commit=$(git rev-parse --verify HEAD) &&
164-
graft="$graft$commit "
164+
graft="$graft$commit " || return 1
165165
done
166166
done &&
167167
printf "%s " $graft >.git/info/grafts &&

t/t6005-rev-list-count.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_expect_success 'setup' '
88
for n in 1 2 3 4 5 ; do
99
echo $n > a &&
1010
git add a &&
11-
git commit -m "$n"
11+
git commit -m "$n" || return 1
1212
done
1313
'
1414

t/t6009-rev-list-parent.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ test_expect_success 'dodecapus' '
124124
git checkout -b root$i five &&
125125
test_commit $i &&
126126
roots="$roots root$i" ||
127-
return
127+
return 1
128128
done &&
129129
git checkout main &&
130130
test_tick &&
@@ -143,7 +143,7 @@ test_expect_success 'ancestors with the same commit time' '
143143
test_tick_keep=$test_tick &&
144144
for i in 1 2 3 4 5 6 7 8; do
145145
test_tick=$test_tick_keep &&
146-
test_commit t$i
146+
test_commit t$i || return 1
147147
done &&
148148
git rev-list t1^! --not t$i >result &&
149149
test_must_be_empty result

t/t6101-rev-parse-parents.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test_expect_success 'setup' '
3232
test_tick &&
3333
git commit --allow-empty -m "$i" &&
3434
commit=$(git rev-parse --verify HEAD) &&
35-
printf "$commit " >>.git/info/grafts
35+
printf "$commit " >>.git/info/grafts || return 1
3636
done
3737
'
3838

t/t6112-rev-list-filters-objects.sh

Lines changed: 4 additions & 4 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

@@ -75,7 +75,7 @@ test_expect_success 'setup r2' '
7575
do
7676
printf "%"$n"s" X > r2/large.$n &&
7777
git -C r2 add large.$n &&
78-
git -C r2 commit -m "$n"
78+
git -C r2 commit -m "$n" || return 1
7979
done
8080
'
8181

@@ -248,7 +248,7 @@ test_expect_success 'setup r3' '
248248
echo "This is file: $n" > r3/$n &&
249249
git -C r3 add $n &&
250250
echo "This is file: dir1/$n" > r3/dir1/$n &&
251-
git -C r3 add dir1/$n
251+
git -C r3 add dir1/$n || return 1
252252
done &&
253253
git -C r3 commit -m "sparse" &&
254254
echo dir1/ >pattern1 &&
@@ -672,7 +672,7 @@ test_expect_success 'rev-list W/ --missing=print' '
672672
673673
for id in `cat expected | sed "s|..|&/|"`
674674
do
675-
rm r1/.git/objects/$id
675+
rm r1/.git/objects/$id || return 1
676676
done &&
677677
678678
git -C r1 rev-list --quiet --missing=print --objects HEAD >revs &&

t/t6120-describe.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ test_expect_success 'name-rev --all' '
262262
>expect.unsorted &&
263263
for rev in $(git rev-list --all)
264264
do
265-
git name-rev $rev >>expect.unsorted
265+
git name-rev $rev >>expect.unsorted || return 1
266266
done &&
267267
sort <expect.unsorted >expect &&
268268
git name-rev --all >actual.unsorted &&
@@ -275,7 +275,7 @@ test_expect_success 'name-rev --stdin' '
275275
for rev in $(git rev-list --all)
276276
do
277277
name=$(git name-rev --name-only $rev) &&
278-
echo "$rev ($name)" >>expect.unsorted
278+
echo "$rev ($name)" >>expect.unsorted || return 1
279279
done &&
280280
sort <expect.unsorted >expect &&
281281
git rev-list --all | git name-rev --stdin >actual.unsorted &&
@@ -395,7 +395,7 @@ EOF" &&
395395
then
396396
echo "from refs/heads/main^0"
397397
fi &&
398-
i=$(($i + 1))
398+
i=$(($i + 1)) || return 1
399399
done | git fast-import &&
400400
git checkout main &&
401401
git tag far-far-away HEAD^ &&

t/t6132-pathspec-exclude.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_expect_success 'setup' '
1111
fi &&
1212
: >$p &&
1313
git add $p &&
14-
git commit -m $p
14+
git commit -m $p || return 1
1515
done &&
1616
git log --oneline --format=%s >actual &&
1717
cat <<EOF >expect &&

t/t6200-fmt-merge-msg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ test_expect_success 'merge-msg lots of commits' '
519519
while test $i -gt 9
520520
do
521521
echo " $i" &&
522-
i=$(($i-1))
522+
i=$(($i-1)) || return 1
523523
done &&
524524
echo " ..."
525525
} >expected &&

t/t6300-for-each-ref.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ test_expect_success ':remotename and :remoteref' '
13381338
echo "${pair#*=}" >expect &&
13391339
git for-each-ref --format="${pair%=*}" \
13401340
refs/heads/main >actual &&
1341-
test_cmp expect actual
1341+
test_cmp expect actual || exit 1
13421342
done &&
13431343
git branch push-simple &&
13441344
git config branch.push-simple.pushRemote from &&

0 commit comments

Comments
 (0)