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 <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
cbe1d9d630e529d3dd240eacf3d1c9799fef702b
16 files changed
+38
-38
t/t4001-diff-rename.sh
+1
-1
@@ -174,7 +174,7 @@ test_expect_success 'setup for many rename source candidates' '
174
do
175
for j in 0 1 2 3 4 5 6 7 8 9;
176
do
177
- echo "$i$j" >"path$i$j"
177
+ echo "$i$j" >"path$i$j" || return 1
178
done
179
done &&
180
git add "path??" &&
t/t4012-diff-binary.sh
+1
-1
@@ -122,7 +122,7 @@ test_expect_success 'diff --stat with binary files and big change count' '
122
i=0 &&
123
while test $i -lt 10000; do
124
echo $i &&
125
- i=$(($i + 1))
125
+ i=$(($i + 1)) || return 1
126
done >textfile &&
127
git add textfile &&
128
git diff --cached --stat binfile textfile >output &&
t/t4014-format-patch.sh
+3
-3
@@ -325,7 +325,7 @@ test_expect_success 'filename length limit' '
325
max=$(
326
for patch in 000[1-9]-*.patch
327
do
328
- echo "$patch" | wc -c
328
+ echo "$patch" | wc -c || exit 1
329
done |
330
sort -nr |
331
head -n 1
@@ -343,7 +343,7 @@ test_expect_success 'filename length limit from config' '
343
max=$(
344
for patch in 000[1-9]-*.patch
345
do
346
- echo "$patch" | wc -c
346
+ echo "$patch" | wc -c || exit 1
347
done |
348
sort -nr |
349
head -n 1
@@ -361,7 +361,7 @@ test_expect_success 'filename limit applies only to basename' '
361
max=$(
362
for patch in patches/000[1-9]-*.patch
363
do
364
- echo "${patch#patches/}" | wc -c
364
+ echo "${patch#patches/}" | wc -c || exit 1
365
done |
366
sort -nr |
367
head -n 1
t/t4015-diff-whitespace.sh
+2
-2
@@ -843,7 +843,7 @@ test_expect_success 'whitespace changes with modification reported (diffstat)' '
843
844
test_expect_success 'whitespace-only changes reported across renames (diffstat)' '
845
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 &&
847
git add x &&
848
git commit -m "base" &&
849
sed -e "5s/^/ /" x >z &&
@@ -859,7 +859,7 @@ test_expect_success 'whitespace-only changes reported across renames (diffstat)'
859
860
test_expect_success 'whitespace-only changes reported across renames' '
861
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 &&
863
git add x &&
864
hash_x=$(git hash-object x) &&
865
before=$(git rev-parse --short "$hash_x") &&
t/t4018-diff-funcname.sh
+1
-1
@@ -75,7 +75,7 @@ test_expect_success 'last regexp must not be negated' '
75
test_expect_success 'setup hunk header tests' '
76
for i in $diffpatterns
77
do
78
- echo "$i-* diff=$i"
78
+ echo "$i-* diff=$i" || return 1
79
done > .gitattributes &&
80
81
# add all test files to the index
t/t4024-diff-optimize-common.sh
+1
-1
@@ -148,7 +148,7 @@ test_expect_success 'diff -U0' '
148
149
for n in $sample
150
do
151
- git diff -U0 file-?$n
151
+ git diff -U0 file-?$n || return 1
152
done | zc >actual &&
153
test_cmp expect actual
154
t/t4038-diff-combined.sh
+1
-1
@@ -100,7 +100,7 @@ test_expect_success 'setup for --cc --raw' '
100
for i in $(test_seq 1 40)
101
do
102
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
104
done
105
'
106
t/t4046-diff-unmerged.sh
+4
-4
@@ -37,7 +37,7 @@ test_expect_success 'diff-files -0' '
37
for path in $paths
38
do
39
>"$path" &&
40
- echo ":000000 100644 $ZERO_OID $ZERO_OID U $path"
40
+ echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" || return 1
41
done >diff-files-0.expect &&
42
git diff-files -0 >diff-files-0.actual &&
43
test_cmp diff-files-0.expect diff-files-0.actual
@@ -50,7 +50,7 @@ test_expect_success 'diff-files -1' '
50
echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" &&
51
case "$path" in
52
x??) echo ":100644 100644 $blob1 $ZERO_OID M $path"
53
- esac
53
+ esac || return 1
54
done >diff-files-1.expect &&
55
git diff-files -1 >diff-files-1.actual &&
56
test_cmp diff-files-1.expect diff-files-1.actual
@@ -63,7 +63,7 @@ test_expect_success 'diff-files -2' '
63
echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" &&
64
case "$path" in
65
?x?) echo ":100644 100644 $blob2 $ZERO_OID M $path"
66
- esac
66
+ esac || return 1
67
done >diff-files-2.expect &&
68
git diff-files -2 >diff-files-2.actual &&
69
test_cmp diff-files-2.expect diff-files-2.actual &&
@@ -78,7 +78,7 @@ test_expect_success 'diff-files -3' '
78
echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" &&
79
case "$path" in
80
??x) echo ":100644 100644 $blob3 $ZERO_OID M $path"
81
- esac
81
+ esac || return 1
82
done >diff-files-3.expect &&
83
git diff-files -3 >diff-files-3.actual &&
84
test_cmp diff-files-3.expect diff-files-3.actual
t/t4049-diff-stat-count.sh
+1
-1
@@ -51,7 +51,7 @@ test_expect_success 'exclude unmerged entries from total file count' '
51
git rm -f d &&
52
for stage in 1 2 3
53
do
54
- sed -e "s/ 0 a/ $stage d/" x
54
+ sed -e "s/ 0 a/ $stage d/" x || return 1
55
done |
56
git update-index --index-info &&
57
echo d >d &&
t/t4052-stat-output.sh
+1
-1
@@ -101,7 +101,7 @@ test_expect_success 'preparation for big change tests' '
101
i=0 &&
102
while test $i -lt 1000
103
do
104
- echo $i && i=$(($i + 1))
104
+ echo $i && i=$(($i + 1)) || return 1
105
done >abcd &&
106
git commit -m message abcd
107
'
t/t4057-diff-combined-paths.sh
+8
-8
@@ -18,13 +18,13 @@ test_expect_success 'trivial merge - combine-diff empty' '
18
for i in $(test_seq 1 9)
19
do
20
echo $i >$i.txt &&
21
- git add $i.txt
21
+ git add $i.txt || return 1
22
done &&
23
git commit -m "init" &&
24
git checkout -b side &&
25
for i in $(test_seq 2 9)
26
do
27
- echo $i/2 >>$i.txt
27
+ echo $i/2 >>$i.txt || return 1
28
done &&
29
git commit -a -m "side 2-9" &&
30
git checkout main &&
@@ -40,14 +40,14 @@ test_expect_success 'only one truly conflicting path' '
40
git checkout side &&
41
for i in $(test_seq 2 9)
42
do
43
- echo $i/3 >>$i.txt
43
+ echo $i/3 >>$i.txt || return 1
44
done &&
45
echo "4side" >>4.txt &&
46
git commit -a -m "side 2-9 +4" &&
47
git checkout main &&
48
for i in $(test_seq 1 9)
49
do
50
- echo $i/3 >>$i.txt
50
+ echo $i/3 >>$i.txt || return 1
51
done &&
52
echo "4main" >>4.txt &&
53
git commit -a -m "main 1-9 +4" &&
@@ -69,13 +69,13 @@ test_expect_success 'merge introduces new file' '
69
git checkout side &&
70
for i in $(test_seq 5 9)
71
do
72
- echo $i/4 >>$i.txt
72
+ echo $i/4 >>$i.txt || return 1
73
done &&
74
git commit -a -m "side 5-9" &&
75
git checkout main &&
76
for i in $(test_seq 1 3)
77
do
78
- echo $i/4 >>$i.txt
78
+ echo $i/4 >>$i.txt || return 1
79
done &&
80
git commit -a -m "main 1-3 +4hello" &&
81
git merge side &&
@@ -90,13 +90,13 @@ test_expect_success 'merge removed a file' '
90
git checkout side &&
91
for i in $(test_seq 5 9)
92
do
93
- echo $i/5 >>$i.txt
93
+ echo $i/5 >>$i.txt || return 1
94
done &&
95
git commit -a -m "side 5-9" &&
96
git checkout main &&
97
for i in $(test_seq 1 3)
98
do
99
- echo $i/4 >>$i.txt
99
+ echo $i/4 >>$i.txt || return 1
100
done &&
101
git commit -a -m "main 1-3" &&
102
git merge side &&
t/t4124-apply-ws-rule.sh
+2
-2
@@ -333,7 +333,7 @@ test_expect_success 'applying beyond EOF requires one non-blank context line' '
333
334
test_expect_success 'tons of blanks at EOF should not apply' '
335
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
336
- test_write_lines "" "" "" ""
336
+ test_write_lines "" "" "" "" || return 1
337
done >one &&
338
git add one &&
339
echo a >>one &&
@@ -396,7 +396,7 @@ test_expect_success 'shrink file with tons of missing blanks at end of file' '
396
test_write_lines a b c >one &&
397
cp one no-blank-lines &&
398
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
399
- test_write_lines "" "" "" ""
399
+ test_write_lines "" "" "" "" || return 1
400
done >>one &&
401
git add one &&
402
echo a >one &&
t/t4138-apply-ws-expansion.sh
+8
-8
@@ -30,7 +30,7 @@ test_expect_success setup '
30
while test $x -lt $n
31
do
32
printf "%63s%d\n" "" $x >>after &&
33
- x=$(( $x + 1 ))
33
+ x=$(( $x + 1 )) || return 1
34
done &&
35
printf "\t%s\n" d e f >>after &&
36
test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
@@ -41,7 +41,7 @@ test_expect_success setup '
41
while test $x -lt $n
42
do
43
printf "%63s%d\n" "" $x >>expect-2 &&
44
- x=$(( $x + 1 ))
44
+ x=$(( $x + 1 )) || return 1
45
done &&
46
printf "%64s\n" d e f >>expect-2 &&
47
@@ -53,7 +53,7 @@ test_expect_success setup '
53
while test $x -lt $n
54
do
55
printf "%63s%02d\n" "" $x >>after &&
56
- x=$(( $x + 1 ))
56
+ x=$(( $x + 1 )) || return 1
57
done &&
58
printf "\t%s\n" d e f >>after &&
59
test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
@@ -64,7 +64,7 @@ test_expect_success setup '
64
while test $x -lt $n
65
do
66
printf "%63s%02d\n" "" $x >>expect-3 &&
67
- x=$(( $x + 1 ))
67
+ x=$(( $x + 1 )) || return 1
68
done &&
69
printf "%64s\n" d e f >>expect-3 &&
70
@@ -74,7 +74,7 @@ test_expect_success setup '
74
while test $x -lt 50
75
do
76
printf "\t%02d\n" $x >>before &&
77
- x=$(( $x + 1 ))
77
+ x=$(( $x + 1 )) || return 1
78
done &&
79
cat before >after &&
80
printf "%64s\n" a b c >>after &&
@@ -82,7 +82,7 @@ test_expect_success setup '
82
do
83
printf "\t%02d\n" $x >>before &&
84
printf "\t%02d\n" $x >>after &&
85
- x=$(( $x + 1 ))
85
+ x=$(( $x + 1 )) || return 1
86
done &&
87
test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
88
sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
@@ -91,7 +91,7 @@ test_expect_success setup '
91
while test $x -lt 50
92
do
93
printf "%63s%02d\n" "" $x >>test-4 &&
94
- x=$(( $x + 1 ))
94
+ x=$(( $x + 1 )) || return 1
95
done &&
96
cat test-4 >expect-4 &&
97
printf "%64s\n" a b c >>expect-4 &&
@@ -99,7 +99,7 @@ test_expect_success setup '
99
do
100
printf "%63s%02d\n" "" $x >>test-4 &&
101
printf "%63s%02d\n" "" $x >>expect-4 &&
102
- x=$(( $x + 1 ))
102
+ x=$(( $x + 1 )) || return 1
103
done &&
104
105
git config core.whitespace tab-in-indent,tabwidth=63 &&
t/t4205-log-pretty-formats.sh
+1
-1
@@ -976,7 +976,7 @@ test_expect_success '%(describe) vs git describe' '
976
else
977
: >expect-contains-bad
978
fi &&
979
- echo "$hash $desc"
979
+ echo "$hash $desc" || return 1
980
done >expect &&
981
test_path_exists expect-contains-good &&
982
test_path_exists expect-contains-bad &&
t/t4211-line-log.sh
+1
-1
@@ -137,7 +137,7 @@ test_expect_success 'range_set_union' '
137
test_seq 1000 > c.c &&
138
git add c.c &&
139
git commit -m "modify many lines" &&
140
- git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done)
140
+ git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c || return 1; done)
141
'
142
143
test_expect_success '-s shows only line-log commits' '
t/t4216-log-bloom.sh
+2
-2
@@ -376,7 +376,7 @@ test_expect_success 'Bloom generation backfills empty commits' '
376
cd empty &&
377
for i in $(test_seq 1 6)
378
do
379
- git commit --allow-empty -m "$i"
379
+ git commit --allow-empty -m "$i" || return 1
380
done &&
381
382
# Generate Bloom filters for empty commits 1-6, two at a time.
@@ -389,7 +389,7 @@ test_expect_success 'Bloom generation backfills empty commits' '
389
test_filter_computed 2 trace.event &&
390
test_filter_not_computed 4 trace.event &&
391
test_filter_trunc_empty 2 trace.event &&
392
- test_filter_trunc_large 0 trace.event
392
+ test_filter_trunc_large 0 trace.event || return 1
393
done &&
394
395
# Finally, make sure that once all commits have filters, that