]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: apply modern idiom for exiting loop upon failure
authorEric Sunshine <sunshine@sunshineco.com>
Thu, 9 Dec 2021 05:11:10 +0000 (00:11 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 18:29:48 +0000 (10:29 -0800)
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>
t/t1050-large.sh
t/t5505-remote.sh
t/t9400-git-cvsserver-server.sh

index 99ff2866b7540bdad6f8462b385f4348a8efd025..0e4267c72385654d6751c07ccb79ee3e98333575 100755 (executable)
@@ -51,27 +51,21 @@ EOF
 test_expect_success 'add a large file or two' '
        git add large1 huge large2 &&
        # 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
        do
                count=$(( $count + 1 )) &&
-               if test_path_is_file "$p" &&
-                  idx=${p%.pack}.idx && test_path_is_file "$idx"
-               then
-                       continue
-               fi
-               bad=t
+               test_path_is_file "$p" &&
+               idx=${p%.pack}.idx &&
+               test_path_is_file "$idx" || return 1
        done &&
-       test -z "$bad" &&
        test $count = 1 &&
        cnt=$(git show-index <"$idx" | wc -l) &&
        test $cnt = 2 &&
        for l in .git/objects/$OIDPATH_REGEX
        do
-               test_path_is_file "$l" || continue
-               bad=t
+               test_path_is_missing "$l" || return 1
        done &&
-       test -z "$bad" &&
 
        # attempt to add another copy of the same
        git add large3 &&
@@ -79,14 +73,10 @@ test_expect_success 'add a large file or two' '
        for p in .git/objects/pack/pack-*.pack
        do
                count=$(( $count + 1 )) &&
-               if test_path_is_file "$p" &&
-                  idx=${p%.pack}.idx && test_path_is_file "$idx"
-               then
-                       continue
-               fi
-               bad=t
+               test_path_is_file "$p" &&
+               idx=${p%.pack}.idx &&
+               test_path_is_file "$idx" || return 1
        done &&
-       test -z "$bad" &&
        test $count = 1
 '
 
index e6e3c8f552cd66fedaccbadb49cb47facb3f3863..5ef8db481cf00a6746732d2d6b34b3baebbf1f31 100755 (executable)
@@ -1332,7 +1332,6 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
        (
                cd test &&
                git tag -a -m "Some tag" some-tag main &&
-               exit_with=true &&
                for type in commit tag tree blob
                do
                        if test "$type" = "blob"
@@ -1348,9 +1347,8 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
                                push origin $oid:dst 2>err &&
                        test_i18ngrep "error: The destination you" err &&
                        test_i18ngrep ! "hint: Did you mean" err ||
-                       exit_with=false
-               done &&
-               $exit_with
+                       exit 1
+               done
        )
 '
 
index 17f988edd268d60e4b4a7dd2074c5566b290554f..ca505748950af7c2933d700f26c05674645e1e85 100755 (executable)
@@ -350,10 +350,9 @@ test_expect_success 'cvs update (subdirectories)' \
        test_cmp "$dir/$filename" "../$dir/$filename"; then
         :
       else
-        echo >failure
+       exit 1
       fi
-    done) &&
-   test ! -f failure'
+    done)'
 
 cd "$WORKDIR"
 test_expect_success 'cvs update (delete file)' \