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>

Eric Sunshine committed Dec 9, 2021 at 00:11 UTC 03949e33f58223dd2d8465f4dd8042e5e581fcef
3 files changed +12 -25
t/t1050-large.sh
+8 -18
@@ -51,27 +51,21 @@ EOF
51 test_expect_success 'add a large file or two' '
52 git add large1 huge large2 &&
53 # make sure we got a single packfile and no loose objects
54 - bad= count=0 idx= &&
54 + count=0 idx= &&
55 for p in .git/objects/pack/pack-*.pack
56 do
57 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
61 done &&
65 - test -z "$bad" &&
62 test $count = 1 &&
63 cnt=$(git show-index <"$idx" | wc -l) &&
64 test $cnt = 2 &&
65 for l in .git/objects/$OIDPATH_REGEX
66 do
71 - test_path_is_file "$l" || continue
72 - bad=t
67 + test_path_is_missing "$l" || return 1
68 done &&
74 - test -z "$bad" &&
69
70 # attempt to add another copy of the same
71 git add large3 &&
@@ -79,14 +73,10 @@ test_expect_success 'add a large file or two' '
73 for p in .git/objects/pack/pack-*.pack
74 do
75 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
79 done &&
89 - test -z "$bad" &&
80 test $count = 1
81 '
82
t/t5505-remote.sh
+2 -4
@@ -1332,7 +1332,6 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
1332 (
1333 cd test &&
1334 git tag -a -m "Some tag" some-tag main &&
1335 - exit_with=true &&
1335 for type in commit tag tree blob
1336 do
1337 if test "$type" = "blob"
@@ -1348,9 +1347,8 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
1347 push origin $oid:dst 2>err &&
1348 test_i18ngrep "error: The destination you" err &&
1349 test_i18ngrep ! "hint: Did you mean" err ||
1351 - exit_with=false
1352 - done &&
1353 - $exit_with
1350 + exit 1
1351 + done
1352 )
1353 '
1354
t/t9400-git-cvsserver-server.sh
+2 -3
@@ -350,10 +350,9 @@ test_expect_success 'cvs update (subdirectories)' \
350 test_cmp "$dir/$filename" "../$dir/$filename"; then
351 :
352 else
353 - echo >failure
353 + exit 1
354 fi
355 - done) &&
356 - test ! -f failure'
355 + done)'
356
357 cd "$WORKDIR"
358 test_expect_success 'cvs update (delete file)' \