]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: detect and signal failure within loop
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 22 Aug 2022 18:26:42 +0000 (18:26 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Aug 2022 19:53:02 +0000 (12:53 -0700)
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>
t/perf/p7527-builtin-fsmonitor.sh
t/t1092-sparse-checkout-compatibility.sh
t/t5329-pack-objects-cruft.sh
t/t6429-merge-sequence-rename-caching.sh

index 9338b9ea008d59f5e81b9e7a01375e68676e3d8d..c3f9a4caa4caadca271982c2e9f872d977c3610b 100755 (executable)
@@ -249,7 +249,7 @@ test_expect_success "Cleanup temp and matrix branches" "
        do
                for fsm_val in $fsm_values
                do
-                       cleanup $uc_val $fsm_val
+                       cleanup $uc_val $fsm_val || return 1
                done
        done
 "
index e13368861cea60f784d2cba255b39afaf1311df6..0302e36fd66ff4e7b6a4003da206574fe4933588 100755 (executable)
@@ -556,7 +556,7 @@ test_expect_success 'blame with pathspec inside sparse definition' '
                        deep/deeper1/a \
                        deep/deeper1/deepest/a
        do
-               test_all_match git blame $file
+               test_all_match git blame $file || return 1
        done
 '
 
@@ -1571,7 +1571,7 @@ test_expect_success 'sparse index is not expanded: blame' '
                        deep/deeper1/a \
                        deep/deeper1/deepest/a
        do
-               ensure_not_expanded blame $file
+               ensure_not_expanded blame $file || return 1
        done
 '
 
@@ -1907,7 +1907,7 @@ test_expect_success 'rm pathspec outside sparse definition' '
                test_sparse_match test_must_fail git rm $file &&
                test_sparse_match test_must_fail git rm --cached $file &&
                test_sparse_match git rm --sparse $file &&
-               test_sparse_match git status --porcelain=v2
+               test_sparse_match git status --porcelain=v2 || return 1
        done &&
 
        cat >folder1-full <<-EOF &&
index 8968f7a08d8700bb22aec956e3f8e50ab2f376bd..6049e2c1d7801050e9aa6ea166e7d332d5b76551 100755 (executable)
@@ -29,7 +29,7 @@ basic_cruft_pack_tests () {
                                while read oid
                                do
                                        path="$objdir/$(test_oid_to_path "$oid")" &&
-                                       printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")"
+                                       printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")" || exit 1
                                done |
                                sort -k1
                        ) >expect &&
@@ -232,7 +232,7 @@ test_expect_success 'cruft tags rescue tagged objects' '
                while read oid
                do
                        test-tool chmtime -1000 \
-                               "$objdir/$(test_oid_to_path $oid)"
+                               "$objdir/$(test_oid_to_path $oid)" || exit 1
                done <objects &&
 
                test-tool chmtime -500 \
@@ -272,7 +272,7 @@ test_expect_success 'cruft commits rescue parents, trees' '
                while read object
                do
                        test-tool chmtime -1000 \
-                               "$objdir/$(test_oid_to_path $object)"
+                               "$objdir/$(test_oid_to_path $object)" || exit 1
                done <objects &&
                test-tool chmtime +500 "$objdir/$(test_oid_to_path \
                        $(git rev-parse HEAD))" &&
@@ -345,7 +345,7 @@ test_expect_success 'expired objects are pruned' '
                while read object
                do
                        test-tool chmtime -1000 \
-                               "$objdir/$(test_oid_to_path $object)"
+                               "$objdir/$(test_oid_to_path $object)" || exit 1
                done <objects &&
 
                keep="$(basename "$(ls $packdir/pack-*.pack)")" &&
index e1ce9199164806abc23955530e4681d1f3cf671e..650b3cd14ffefdf1cbb4a56661bcc170cde04cf1 100755 (executable)
@@ -725,7 +725,7 @@ test_expect_success 'avoid assuming we detected renames' '
                mkdir unrelated &&
                for i in $(test_seq 1 10)
                do
-                       >unrelated/$i
+                       >unrelated/$i || exit 1
                done &&
                test_seq  2 10 >numbers &&
                test_seq 12 20 >values &&