Skip to content

Commit cbe1d9d

Browse files
sunshinecogitster
authored andcommitted
t4000-t4999: 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 db5875a commit cbe1d9d

16 files changed

+38
-38
lines changed

t/t4001-diff-rename.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ test_expect_success 'setup for many rename source candidates' '
174174
do
175175
for j in 0 1 2 3 4 5 6 7 8 9;
176176
do
177-
echo "$i$j" >"path$i$j"
177+
echo "$i$j" >"path$i$j" || return 1
178178
done
179179
done &&
180180
git add "path??" &&

t/t4012-diff-binary.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ test_expect_success 'diff --stat with binary files and big change count' '
122122
i=0 &&
123123
while test $i -lt 10000; do
124124
echo $i &&
125-
i=$(($i + 1))
125+
i=$(($i + 1)) || return 1
126126
done >textfile &&
127127
git add textfile &&
128128
git diff --cached --stat binfile textfile >output &&

t/t4014-format-patch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ test_expect_success 'filename length limit' '
325325
max=$(
326326
for patch in 000[1-9]-*.patch
327327
do
328-
echo "$patch" | wc -c
328+
echo "$patch" | wc -c || exit 1
329329
done |
330330
sort -nr |
331331
head -n 1
@@ -343,7 +343,7 @@ test_expect_success 'filename length limit from config' '
343343
max=$(
344344
for patch in 000[1-9]-*.patch
345345
do
346-
echo "$patch" | wc -c
346+
echo "$patch" | wc -c || exit 1
347347
done |
348348
sort -nr |
349349
head -n 1
@@ -361,7 +361,7 @@ test_expect_success 'filename limit applies only to basename' '
361361
max=$(
362362
for patch in patches/000[1-9]-*.patch
363363
do
364-
echo "${patch#patches/}" | wc -c
364+
echo "${patch#patches/}" | wc -c || exit 1
365365
done |
366366
sort -nr |
367367
head -n 1

t/t4015-diff-whitespace.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ test_expect_success 'whitespace changes with modification reported (diffstat)' '
843843

844844
test_expect_success 'whitespace-only changes reported across renames (diffstat)' '
845845
git reset --hard &&
846-
for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
846+
for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i" || return 1; done >x &&
847847
git add x &&
848848
git commit -m "base" &&
849849
sed -e "5s/^/ /" x >z &&
@@ -859,7 +859,7 @@ test_expect_success 'whitespace-only changes reported across renames (diffstat)'
859859

860860
test_expect_success 'whitespace-only changes reported across renames' '
861861
git reset --hard HEAD~1 &&
862-
for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
862+
for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i" || return 1; done >x &&
863863
git add x &&
864864
hash_x=$(git hash-object x) &&
865865
before=$(git rev-parse --short "$hash_x") &&

t/t4018-diff-funcname.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test_expect_success 'last regexp must not be negated' '
7575
test_expect_success 'setup hunk header tests' '
7676
for i in $diffpatterns
7777
do
78-
echo "$i-* diff=$i"
78+
echo "$i-* diff=$i" || return 1
7979
done > .gitattributes &&
8080
8181
# add all test files to the index

t/t4024-diff-optimize-common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ test_expect_success 'diff -U0' '
148148
149149
for n in $sample
150150
do
151-
git diff -U0 file-?$n
151+
git diff -U0 file-?$n || return 1
152152
done | zc >actual &&
153153
test_cmp expect actual
154154

t/t4038-diff-combined.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test_expect_success 'setup for --cc --raw' '
100100
for i in $(test_seq 1 40)
101101
do
102102
blob=$(echo file$i | git hash-object --stdin -w) &&
103-
trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF"
103+
trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF" || return 1
104104
done
105105
'
106106

t/t4046-diff-unmerged.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test_expect_success 'diff-files -0' '
3737
for path in $paths
3838
do
3939
>"$path" &&
40-
echo ":000000 100644 $ZERO_OID $ZERO_OID U $path"
40+
echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" || return 1
4141
done >diff-files-0.expect &&
4242
git diff-files -0 >diff-files-0.actual &&
4343
test_cmp diff-files-0.expect diff-files-0.actual
@@ -50,7 +50,7 @@ test_expect_success 'diff-files -1' '
5050
echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" &&
5151
case "$path" in
5252
x??) echo ":100644 100644 $blob1 $ZERO_OID M $path"
53-
esac
53+
esac || return 1
5454
done >diff-files-1.expect &&
5555
git diff-files -1 >diff-files-1.actual &&
5656
test_cmp diff-files-1.expect diff-files-1.actual
@@ -63,7 +63,7 @@ test_expect_success 'diff-files -2' '
6363
echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" &&
6464
case "$path" in
6565
?x?) echo ":100644 100644 $blob2 $ZERO_OID M $path"
66-
esac
66+
esac || return 1
6767
done >diff-files-2.expect &&
6868
git diff-files -2 >diff-files-2.actual &&
6969
test_cmp diff-files-2.expect diff-files-2.actual &&
@@ -78,7 +78,7 @@ test_expect_success 'diff-files -3' '
7878
echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" &&
7979
case "$path" in
8080
??x) echo ":100644 100644 $blob3 $ZERO_OID M $path"
81-
esac
81+
esac || return 1
8282
done >diff-files-3.expect &&
8383
git diff-files -3 >diff-files-3.actual &&
8484
test_cmp diff-files-3.expect diff-files-3.actual

t/t4049-diff-stat-count.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test_expect_success 'exclude unmerged entries from total file count' '
5151
git rm -f d &&
5252
for stage in 1 2 3
5353
do
54-
sed -e "s/ 0 a/ $stage d/" x
54+
sed -e "s/ 0 a/ $stage d/" x || return 1
5555
done |
5656
git update-index --index-info &&
5757
echo d >d &&

t/t4052-stat-output.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ test_expect_success 'preparation for big change tests' '
101101
i=0 &&
102102
while test $i -lt 1000
103103
do
104-
echo $i && i=$(($i + 1))
104+
echo $i && i=$(($i + 1)) || return 1
105105
done >abcd &&
106106
git commit -m message abcd
107107
'

0 commit comments

Comments
 (0)