Skip to content

Commit db5875a

Browse files
sunshinecogitster
authored andcommitted
t0000-t3999: 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 efe26b9 commit db5875a

31 files changed

+55
-55
lines changed

t/perf/p0100-globbing.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ test_expect_success 'setup' '
1919
printf "a" >>refname &&
2020
for j in $(test_seq 1 $i)
2121
do
22-
printf "a*" >>refglob.$i
22+
printf "a*" >>refglob.$i || return 1
2323
done &&
24-
echo b >>refglob.$i
24+
echo b >>refglob.$i || return 1
2525
done &&
2626
test_commit test $(cat refname).t "" $(cat refname).t
2727
'

t/perf/p1400-update-ref.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_expect_success "setup" '
1313
do
1414
printf "start\ncreate refs/heads/%d PRE\ncommit\n" $i &&
1515
printf "start\nupdate refs/heads/%d POST PRE\ncommit\n" $i &&
16-
printf "start\ndelete refs/heads/%d POST\ncommit\n" $i
16+
printf "start\ndelete refs/heads/%d POST\ncommit\n" $i || return 1
1717
done >instructions
1818
'
1919

@@ -22,7 +22,7 @@ test_perf "update-ref" '
2222
do
2323
git update-ref refs/heads/branch PRE &&
2424
git update-ref refs/heads/branch POST PRE &&
25-
git update-ref -d refs/heads/branch
25+
git update-ref -d refs/heads/branch || return 1
2626
done
2727
'
2828

t/perf/p1451-fsck-skip-list.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_expect_success "setup $n bad commits" '
1515
echo "committer C <[email protected]> 1234567890 +0000" &&
1616
echo "data <<EOF" &&
1717
echo "$i.Q." &&
18-
echo "EOF"
18+
echo "EOF" || return 1
1919
done | q_to_nul | git fast-import
2020
'
2121

t/perf/p3400-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test_expect_success 'setup rebasing on top of a lot of changes' '
2222
git add unrelated-file$i &&
2323
test_tick &&
2424
git commit -m commit$i-reverse unrelated-file$i ||
25-
break
25+
return 1
2626
done &&
2727
git checkout to-rebase &&
2828
test_commit our-patch interesting-file

t/perf/p5302-pack-index.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test_expect_success 'set up thread-counting tests' '
2222
while test $t -gt 0
2323
do
2424
threads="$t $threads" &&
25-
t=$((t / 2))
25+
t=$((t / 2)) || return 1
2626
done
2727
'
2828

t/perf/p5303-many-packs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ test_expect_success 'generate lots of packs' '
130130
echo "data <<EOF" &&
131131
echo "blob $i" &&
132132
echo "EOF" &&
133-
echo "checkpoint"
133+
echo "checkpoint" || return 1
134134
done |
135135
git -c fastimport.unpackLimit=0 fast-import
136136
'

t/perf/p7519-fsmonitor.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ test_expect_success "one time repo setup" '
119119
fi &&
120120
121121
mkdir 1_file 10_files 100_files 1000_files 10000_files &&
122-
for i in $(test_seq 1 10); do touch 10_files/$i; done &&
123-
for i in $(test_seq 1 100); do touch 100_files/$i; done &&
124-
for i in $(test_seq 1 1000); do touch 1000_files/$i; done &&
125-
for i in $(test_seq 1 10000); do touch 10000_files/$i; done &&
122+
for i in $(test_seq 1 10); do touch 10_files/$i || return 1; done &&
123+
for i in $(test_seq 1 100); do touch 100_files/$i || return 1; done &&
124+
for i in $(test_seq 1 1000); do touch 1000_files/$i || return 1; done &&
125+
for i in $(test_seq 1 10000); do touch 10000_files/$i || return 1; done &&
126126
git add 1_file 10_files 100_files 1000_files 10000_files &&
127127
git commit -qm "Add files" &&
128128

t/t0008-ignores.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ test_expect_success 'setup' '
200200
do
201201
: >$dir/not-ignored &&
202202
: >$dir/ignored-and-untracked &&
203-
: >$dir/ignored-but-in-index
203+
: >$dir/ignored-but-in-index || return 1
204204
done &&
205205
git add -f ignored-but-in-index a/ignored-but-in-index &&
206206
cat <<-\EOF >a/.gitignore &&

t/t0011-hashmap.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ test_expect_success 'grow / shrink' '
220220
for n in $(test_seq 51)
221221
do
222222
echo put key$n value$n >> in &&
223-
echo NULL >> expect
223+
echo NULL >> expect || return 1
224224
done &&
225225
echo size >> in &&
226226
echo 64 51 >> expect &&
@@ -231,7 +231,7 @@ test_expect_success 'grow / shrink' '
231231
for n in $(test_seq 12)
232232
do
233233
echo remove key$n >> in &&
234-
echo value$n >> expect
234+
echo value$n >> expect || return 1
235235
done &&
236236
echo size >> in &&
237237
echo 256 40 >> expect &&

t/t0021-conversion.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ test_expect_success 'required filter with absent smudge field' '
285285
test_expect_success 'filtering large input to small output should use little memory' '
286286
test_config filter.devnull.clean "cat >/dev/null" &&
287287
test_config filter.devnull.required true &&
288-
for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
288+
for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB &&
289289
echo "30MB filter=devnull" >.gitattributes &&
290290
GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
291291
'
@@ -303,7 +303,7 @@ test_expect_success 'filter that does not read is fine' '
303303
test_expect_success EXPENSIVE 'filter large file' '
304304
test_config filter.largefile.smudge cat &&
305305
test_config filter.largefile.clean cat &&
306-
for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
306+
for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB &&
307307
echo "2GB filter=largefile" >.gitattributes &&
308308
git add 2GB 2>err &&
309309
test_must_be_empty err &&
@@ -643,7 +643,7 @@ test_expect_success PERL 'required process filter should process multiple packet
643643
for FILE in "$TEST_ROOT"/*.file
644644
do
645645
cp "$FILE" . &&
646-
rot13.sh <"$FILE" >"$FILE.rot13"
646+
rot13.sh <"$FILE" >"$FILE.rot13" || return 1
647647
done &&
648648
649649
echo "*.file filter=protocol" >.gitattributes &&
@@ -682,7 +682,7 @@ test_expect_success PERL 'required process filter should process multiple packet
682682
683683
for FILE in *.file
684684
do
685-
test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
685+
test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE || return 1
686686
done
687687
)
688688
'

0 commit comments

Comments
 (0)