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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Aug 22, 2022 at 18:26 UTC 0e66bc1b215b1dd2b0f05c5777eb8ee2ae4e9523
4 files changed +9 -9
t/perf/p7527-builtin-fsmonitor.sh
+1 -1
@@ -249,7 +249,7 @@ test_expect_success "Cleanup temp and matrix branches" "
249 do
250 for fsm_val in $fsm_values
251 do
252 - cleanup $uc_val $fsm_val
252 + cleanup $uc_val $fsm_val || return 1
253 done
254 done
255 "
t/t1092-sparse-checkout-compatibility.sh
+3 -3
@@ -556,7 +556,7 @@ test_expect_success 'blame with pathspec inside sparse definition' '
556 deep/deeper1/a \
557 deep/deeper1/deepest/a
558 do
559 - test_all_match git blame $file
559 + test_all_match git blame $file || return 1
560 done
561 '
562
@@ -1571,7 +1571,7 @@ test_expect_success 'sparse index is not expanded: blame' '
1571 deep/deeper1/a \
1572 deep/deeper1/deepest/a
1573 do
1574 - ensure_not_expanded blame $file
1574 + ensure_not_expanded blame $file || return 1
1575 done
1576 '
1577
@@ -1907,7 +1907,7 @@ test_expect_success 'rm pathspec outside sparse definition' '
1907 test_sparse_match test_must_fail git rm $file &&
1908 test_sparse_match test_must_fail git rm --cached $file &&
1909 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
1911 done &&
1912
1913 cat >folder1-full <<-EOF &&
t/t5329-pack-objects-cruft.sh
+4 -4
@@ -29,7 +29,7 @@ basic_cruft_pack_tests () {
29 while read oid
30 do
31 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
33 done |
34 sort -k1
35 ) >expect &&
@@ -232,7 +232,7 @@ test_expect_success 'cruft tags rescue tagged objects' '
232 while read oid
233 do
234 test-tool chmtime -1000 \
235 - "$objdir/$(test_oid_to_path $oid)"
235 + "$objdir/$(test_oid_to_path $oid)" || exit 1
236 done <objects &&
237
238 test-tool chmtime -500 \
@@ -272,7 +272,7 @@ test_expect_success 'cruft commits rescue parents, trees' '
272 while read object
273 do
274 test-tool chmtime -1000 \
275 - "$objdir/$(test_oid_to_path $object)"
275 + "$objdir/$(test_oid_to_path $object)" || exit 1
276 done <objects &&
277 test-tool chmtime +500 "$objdir/$(test_oid_to_path \
278 $(git rev-parse HEAD))" &&
@@ -345,7 +345,7 @@ test_expect_success 'expired objects are pruned' '
345 while read object
346 do
347 test-tool chmtime -1000 \
348 - "$objdir/$(test_oid_to_path $object)"
348 + "$objdir/$(test_oid_to_path $object)" || exit 1
349 done <objects &&
350
351 keep="$(basename "$(ls $packdir/pack-*.pack)")" &&
t/t6429-merge-sequence-rename-caching.sh
+1 -1
@@ -725,7 +725,7 @@ test_expect_success 'avoid assuming we detected renames' '
725 mkdir unrelated &&
726 for i in $(test_seq 1 10)
727 do
728 - >unrelated/$i
728 + >unrelated/$i || exit 1
729 done &&
730 test_seq 2 10 >numbers &&
731 test_seq 12 20 >values &&