tests: apply modern idiom for exiting loop upon failure

Rather than maintaining a flag indicating a failure within a loop and
aborting the test when the loop ends if the flag is set, modern practice
is to signal the failure immediately by exiting the loop early via
`return 1` (or `exit 1` if inside a subshell). Simplify these loops by
following the modern idiom.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Eric Sunshine 2021-12-09 00:11:10 -05:00 committed by Junio C Hamano
parent 77b1d9f355
commit 03949e33f5
3 changed files with 12 additions and 25 deletions

View File

@ -51,27 +51,21 @@ EOF
test_expect_success 'add a large file or two' ' test_expect_success 'add a large file or two' '
git add large1 huge large2 && git add large1 huge large2 &&
# make sure we got a single packfile and no loose objects # make sure we got a single packfile and no loose objects
bad= count=0 idx= && count=0 idx= &&
for p in .git/objects/pack/pack-*.pack for p in .git/objects/pack/pack-*.pack
do do
count=$(( $count + 1 )) && count=$(( $count + 1 )) &&
if test_path_is_file "$p" && test_path_is_file "$p" &&
idx=${p%.pack}.idx && test_path_is_file "$idx" idx=${p%.pack}.idx &&
then test_path_is_file "$idx" || return 1
continue
fi
bad=t
done && done &&
test -z "$bad" &&
test $count = 1 && test $count = 1 &&
cnt=$(git show-index <"$idx" | wc -l) && cnt=$(git show-index <"$idx" | wc -l) &&
test $cnt = 2 && test $cnt = 2 &&
for l in .git/objects/$OIDPATH_REGEX for l in .git/objects/$OIDPATH_REGEX
do do
test_path_is_file "$l" || continue test_path_is_missing "$l" || return 1
bad=t
done && done &&
test -z "$bad" &&
# attempt to add another copy of the same # attempt to add another copy of the same
git add large3 && git add large3 &&
@ -79,14 +73,10 @@ test_expect_success 'add a large file or two' '
for p in .git/objects/pack/pack-*.pack for p in .git/objects/pack/pack-*.pack
do do
count=$(( $count + 1 )) && count=$(( $count + 1 )) &&
if test_path_is_file "$p" && test_path_is_file "$p" &&
idx=${p%.pack}.idx && test_path_is_file "$idx" idx=${p%.pack}.idx &&
then test_path_is_file "$idx" || return 1
continue
fi
bad=t
done && done &&
test -z "$bad" &&
test $count = 1 test $count = 1
' '

View File

@ -1332,7 +1332,6 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
( (
cd test && cd test &&
git tag -a -m "Some tag" some-tag main && git tag -a -m "Some tag" some-tag main &&
exit_with=true &&
for type in commit tag tree blob for type in commit tag tree blob
do do
if test "$type" = "blob" if test "$type" = "blob"
@ -1348,9 +1347,8 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
push origin $oid:dst 2>err && push origin $oid:dst 2>err &&
test_i18ngrep "error: The destination you" err && test_i18ngrep "error: The destination you" err &&
test_i18ngrep ! "hint: Did you mean" err || test_i18ngrep ! "hint: Did you mean" err ||
exit_with=false exit 1
done && done
$exit_with
) )
' '

View File

@ -350,10 +350,9 @@ test_expect_success 'cvs update (subdirectories)' \
test_cmp "$dir/$filename" "../$dir/$filename"; then test_cmp "$dir/$filename" "../$dir/$filename"; then
: :
else else
echo >failure exit 1
fi fi
done) && done)'
test ! -f failure'
cd "$WORKDIR" cd "$WORKDIR"
test_expect_success 'cvs update (delete file)' \ test_expect_success 'cvs update (delete file)' \