Skip to content

Commit 03949e3

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77b1d9f commit 03949e3

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

t/t1050-large.sh

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,42 +51,32 @@ EOF
5151
test_expect_success 'add a large file or two' '
5252
git add large1 huge large2 &&
5353
# make sure we got a single packfile and no loose objects
54-
bad= count=0 idx= &&
54+
count=0 idx= &&
5555
for p in .git/objects/pack/pack-*.pack
5656
do
5757
count=$(( $count + 1 )) &&
58-
if test_path_is_file "$p" &&
59-
idx=${p%.pack}.idx && test_path_is_file "$idx"
60-
then
61-
continue
62-
fi
63-
bad=t
58+
test_path_is_file "$p" &&
59+
idx=${p%.pack}.idx &&
60+
test_path_is_file "$idx" || return 1
6461
done &&
65-
test -z "$bad" &&
6662
test $count = 1 &&
6763
cnt=$(git show-index <"$idx" | wc -l) &&
6864
test $cnt = 2 &&
6965
for l in .git/objects/$OIDPATH_REGEX
7066
do
71-
test_path_is_file "$l" || continue
72-
bad=t
67+
test_path_is_missing "$l" || return 1
7368
done &&
74-
test -z "$bad" &&
7569
7670
# attempt to add another copy of the same
7771
git add large3 &&
7872
bad= count=0 &&
7973
for p in .git/objects/pack/pack-*.pack
8074
do
8175
count=$(( $count + 1 )) &&
82-
if test_path_is_file "$p" &&
83-
idx=${p%.pack}.idx && test_path_is_file "$idx"
84-
then
85-
continue
86-
fi
87-
bad=t
76+
test_path_is_file "$p" &&
77+
idx=${p%.pack}.idx &&
78+
test_path_is_file "$idx" || return 1
8879
done &&
89-
test -z "$bad" &&
9080
test $count = 1
9181
'
9282

t/t5505-remote.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,6 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
13321332
(
13331333
cd test &&
13341334
git tag -a -m "Some tag" some-tag main &&
1335-
exit_with=true &&
13361335
for type in commit tag tree blob
13371336
do
13381337
if test "$type" = "blob"
@@ -1348,9 +1347,8 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
13481347
push origin $oid:dst 2>err &&
13491348
test_i18ngrep "error: The destination you" err &&
13501349
test_i18ngrep ! "hint: Did you mean" err ||
1351-
exit_with=false
1352-
done &&
1353-
$exit_with
1350+
exit 1
1351+
done
13541352
)
13551353
'
13561354

t/t9400-git-cvsserver-server.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,9 @@ test_expect_success 'cvs update (subdirectories)' \
350350
test_cmp "$dir/$filename" "../$dir/$filename"; then
351351
:
352352
else
353-
echo >failure
353+
exit 1
354354
fi
355-
done) &&
356-
test ! -f failure'
355+
done)'
357356

358357
cd "$WORKDIR"
359358
test_expect_success 'cvs update (delete file)' \

0 commit comments

Comments
 (0)