Skip to content

Commit 0e66bc1

Browse files
sunshinecogitster
authored andcommitted
t: 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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 625ff5c commit 0e66bc1

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

t/perf/p7527-builtin-fsmonitor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ test_expect_success "Cleanup temp and matrix branches" "
249249
do
250250
for fsm_val in $fsm_values
251251
do
252-
cleanup $uc_val $fsm_val
252+
cleanup $uc_val $fsm_val || return 1
253253
done
254254
done
255255
"

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ test_expect_success 'blame with pathspec inside sparse definition' '
556556
deep/deeper1/a \
557557
deep/deeper1/deepest/a
558558
do
559-
test_all_match git blame $file
559+
test_all_match git blame $file || return 1
560560
done
561561
'
562562

@@ -1571,7 +1571,7 @@ test_expect_success 'sparse index is not expanded: blame' '
15711571
deep/deeper1/a \
15721572
deep/deeper1/deepest/a
15731573
do
1574-
ensure_not_expanded blame $file
1574+
ensure_not_expanded blame $file || return 1
15751575
done
15761576
'
15771577

@@ -1907,7 +1907,7 @@ test_expect_success 'rm pathspec outside sparse definition' '
19071907
test_sparse_match test_must_fail git rm $file &&
19081908
test_sparse_match test_must_fail git rm --cached $file &&
19091909
test_sparse_match git rm --sparse $file &&
1910-
test_sparse_match git status --porcelain=v2
1910+
test_sparse_match git status --porcelain=v2 || return 1
19111911
done &&
19121912
19131913
cat >folder1-full <<-EOF &&

t/t5329-pack-objects-cruft.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ basic_cruft_pack_tests () {
2929
while read oid
3030
do
3131
path="$objdir/$(test_oid_to_path "$oid")" &&
32-
printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")"
32+
printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")" || exit 1
3333
done |
3434
sort -k1
3535
) >expect &&
@@ -232,7 +232,7 @@ test_expect_success 'cruft tags rescue tagged objects' '
232232
while read oid
233233
do
234234
test-tool chmtime -1000 \
235-
"$objdir/$(test_oid_to_path $oid)"
235+
"$objdir/$(test_oid_to_path $oid)" || exit 1
236236
done <objects &&
237237
238238
test-tool chmtime -500 \
@@ -272,7 +272,7 @@ test_expect_success 'cruft commits rescue parents, trees' '
272272
while read object
273273
do
274274
test-tool chmtime -1000 \
275-
"$objdir/$(test_oid_to_path $object)"
275+
"$objdir/$(test_oid_to_path $object)" || exit 1
276276
done <objects &&
277277
test-tool chmtime +500 "$objdir/$(test_oid_to_path \
278278
$(git rev-parse HEAD))" &&
@@ -345,7 +345,7 @@ test_expect_success 'expired objects are pruned' '
345345
while read object
346346
do
347347
test-tool chmtime -1000 \
348-
"$objdir/$(test_oid_to_path $object)"
348+
"$objdir/$(test_oid_to_path $object)" || exit 1
349349
done <objects &&
350350
351351
keep="$(basename "$(ls $packdir/pack-*.pack)")" &&

t/t6429-merge-sequence-rename-caching.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ test_expect_success 'avoid assuming we detected renames' '
725725
mkdir unrelated &&
726726
for i in $(test_seq 1 10)
727727
do
728-
>unrelated/$i
728+
>unrelated/$i || exit 1
729729
done &&
730730
test_seq 2 10 >numbers &&
731731
test_seq 12 20 >values &&

0 commit comments

Comments
 (0)