From: "Eric Sunshine via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Elijah Newren <newren@gmail.com>,
Fabian Stelzer <fs@gigacodes.de>,
Lessley Dennington <lessleydennington@gmail.com>,
Eric Sunshine <sunshine@sunshineco.com>,
Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH 3/3] t: detect and signal failure within loop
Date: Mon, 22 Aug 2022 18:26:42 +0000 [thread overview]
Message-ID: <31a962fd5070d68964e545fb5506d795e8845ec3.1661192802.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1312.git.git.1661192802.gitgitgadget@gmail.com>
From: Eric Sunshine <sunshine@sunshineco.com>
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>
---
t/perf/p7527-builtin-fsmonitor.sh | 2 +-
t/t1092-sparse-checkout-compatibility.sh | 6 +++---
t/t5329-pack-objects-cruft.sh | 8 ++++----
t/t6429-merge-sequence-rename-caching.sh | 2 +-
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/t/perf/p7527-builtin-fsmonitor.sh b/t/perf/p7527-builtin-fsmonitor.sh
index 9338b9ea008..c3f9a4caa4c 100755
--- a/t/perf/p7527-builtin-fsmonitor.sh
+++ b/t/perf/p7527-builtin-fsmonitor.sh
@@ -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
"
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index e13368861ce..0302e36fd66 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -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 &&
diff --git a/t/t5329-pack-objects-cruft.sh b/t/t5329-pack-objects-cruft.sh
index 8968f7a08d8..6049e2c1d78 100755
--- a/t/t5329-pack-objects-cruft.sh
+++ b/t/t5329-pack-objects-cruft.sh
@@ -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)")" &&
diff --git a/t/t6429-merge-sequence-rename-caching.sh b/t/t6429-merge-sequence-rename-caching.sh
index e1ce9199164..650b3cd14ff 100755
--- a/t/t6429-merge-sequence-rename-caching.sh
+++ b/t/t6429-merge-sequence-rename-caching.sh
@@ -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 &&
--
gitgitgadget
next prev parent reply other threads:[~2022-08-22 18:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 18:26 [PATCH 0/3] tests: fix broken &&-chains & abort loops on error Eric Sunshine via GitGitGadget
2022-08-22 18:26 ` [PATCH 1/3] t2407: fix broken &&-chains in compound statement Eric Sunshine via GitGitGadget
2022-08-22 18:26 ` [PATCH 2/3] t1092: fix buggy sparse "blame" test Eric Sunshine via GitGitGadget
2022-08-22 20:09 ` Derrick Stolee
2022-08-22 18:26 ` Eric Sunshine via GitGitGadget [this message]
2022-08-22 20:22 ` [PATCH 3/3] t: detect and signal failure within loop Junio C Hamano
2022-08-22 20:59 ` Junio C Hamano
2022-08-23 6:30 ` Johannes Sixt
2022-08-23 3:05 ` Elijah Newren
2022-08-28 4:50 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31a962fd5070d68964e545fb5506d795e8845ec3.1661192802.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=fs@gigacodes.de \
--cc=git@vger.kernel.org \
--cc=lessleydennington@gmail.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).