]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: simplify by dropping unnecessary `for` loops
authorEric Sunshine <sunshine@sunshineco.com>
Thu, 9 Dec 2021 05:11:11 +0000 (00:11 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 18:29:48 +0000 (10:29 -0800)
Rather than manually looping over a set of items and plugging those
items into a template string which is printed repeatedly, achieve the
same effect by taking advantage of `printf` which loops over its
arguments automatically.

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/t3005-ls-files-relative.sh
t/t3600-rm.sh
t/t4025-hunk-header.sh
t/t4125-apply-ws-fuzz.sh
t/t6416-recursive-corner-cases.sh
t/t7110-reset-merge.sh
t/t9400-git-cvsserver-server.sh

index 6ba8b589cd00d3ad401f4018dc0eed7be1b54e05..fbfa210a50b2906e57853095a2830f3bc6e18136 100755 (executable)
@@ -39,10 +39,7 @@ test_expect_success 'ls-files with mixed levels' '
 test_expect_success 'ls-files -c' '
        (
                cd top/sub &&
-               for f in ../y*
-               do
-                       echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git"
-               done >expect.err &&
+               printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../y* >expect.err &&
                echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
                ls ../x* >expect.out &&
                test_must_fail git ls-files -c --error-unmatch ../[xy]* >actual.out 2>actual.err &&
@@ -54,10 +51,7 @@ test_expect_success 'ls-files -c' '
 test_expect_success 'ls-files -o' '
        (
                cd top/sub &&
-               for f in ../x*
-               do
-                       echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git"
-               done >expect.err &&
+               printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../x* >expect.err &&
                echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
                ls ../y* >expect.out &&
                test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err &&
index ed3952eb98bafb92581bacdfc453d3dfba3ca41e..e74a318ac33ac00d10e6517b10b838ac8e0c899a 100755 (executable)
@@ -274,10 +274,7 @@ test_expect_success 'Resolving by removal is not a warning-worthy event' '
        git reset -q --hard &&
        test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
        blob=$(echo blob | git hash-object -w --stdin) &&
-       for stage in 1 2 3
-       do
-               echo "100644 $blob $stage       blob"
-       done | git update-index --index-info &&
+       printf "100644 $blob %d\tblob\n" 1 2 3 | git update-index --index-info &&
        git rm blob >msg 2>&1 &&
        test_i18ngrep ! "needs merge" msg &&
        test_must_fail git ls-files -s --error-unmatch blob
index 6356961de46c78f5168ab437b9aff50fc979afd0..5397cb7d42d748054eb5a244415c2f5062e3eca2 100755 (executable)
@@ -14,15 +14,9 @@ test_expect_success setup '
 
        (
                echo "A $NS" &&
-               for c in B C D E F G H I J K
-               do
-                       echo "  $c"
-               done &&
+               printf "  %s\n" B C D E F G H I J K &&
                echo "L  $NS" &&
-               for c in M N O P Q R S T U V
-               do
-                       echo "  $c"
-               done
+               printf "  %s\n" M N O P Q R S T U V
        ) >file &&
        git add file &&
 
index 9671de799949f8f67f906cd3db907e3a53cf4eef..090987c89b24b4795bcb80c0461e5c90f3fe5b3b 100755 (executable)
@@ -10,10 +10,7 @@ test_expect_success setup '
        git add file &&
 
        # file-0 is full of whitespace breakages
-       for l in a bb c d eeee f ggg h
-       do
-               echo "$l "
-       done >file-0 &&
+       printf "%s \n" a bb c d eeee f ggg h >file-0 &&
 
        # patch-0 creates a whitespace broken file
        cat file-0 >file &&
index 84f50823666671e54328670dbc7e370600fd1a51..690c8482b13a3763b223be19799ce22197cd383c 100755 (executable)
@@ -24,14 +24,8 @@ test_expect_success 'setup basic criss-cross + rename with no modifications' '
                cd basic-rename &&
 
                ten="0 1 2 3 4 5 6 7 8 9" &&
-               for i in $ten
-               do
-                       echo line $i in a sample file
-               done >one &&
-               for i in $ten
-               do
-                       echo line $i in another sample file
-               done >two &&
+               printf "line %d in a sample file\n" $ten >one &&
+               printf "line %d in another sample file\n" $ten >two &&
                git add one two &&
                test_tick && git commit -m initial &&
 
@@ -96,14 +90,8 @@ test_expect_success 'setup criss-cross + rename merges with basic modification'
                cd rename-modify &&
 
                ten="0 1 2 3 4 5 6 7 8 9" &&
-               for i in $ten
-               do
-                       echo line $i in a sample file
-               done >one &&
-               for i in $ten
-               do
-                       echo line $i in another sample file
-               done >two &&
+               printf "line %d in a sample file\n" $ten >one &&
+               printf "line %d in another sample file\n" $ten >two &&
                git add one two &&
                test_tick && git commit -m initial &&
 
@@ -1588,10 +1576,7 @@ test_expect_success 'setup nested conflicts' '
                cd nested_conflicts &&
 
                # Create some related files now
-               for i in $(test_seq 1 10)
-               do
-                       echo Random base content line $i
-               done >initial &&
+               printf "Random base content line %d\n" $(test_seq 1 10) >initial &&
 
                cp initial b_L1 &&
                cp initial b_R1 &&
@@ -1777,10 +1762,7 @@ test_expect_success 'setup virtual merge base with nested conflicts' '
                cd virtual_merge_base_has_nested_conflicts &&
 
                # Create some related files now
-               for i in $(test_seq 1 10)
-               do
-                       echo Random base content line $i
-               done >content &&
+               printf "Random base content line %d\n" $(test_seq 1 10) >content &&
 
                # Setup original commit
                git add content &&
index a82a07a04a8500cdac2cfb7ef39fb3f5981f437f..3d62e10b53fe16fd2eae0d0fa0363d8839f97b95 100755 (executable)
@@ -8,7 +8,7 @@ test_description='Tests for "git reset" with "--merge" and "--keep" options'
 . ./test-lib.sh
 
 test_expect_success setup '
-    for i in 1 2 3; do echo line $i; done >file1 &&
+    printf "line %d\n" 1 2 3 >file1 &&
     cat file1 >file2 &&
     git add file1 file2 &&
     test_tick &&
index ca505748950af7c2933d700f26c05674645e1e85..567d7f2bb819254ad24b7735e1d64f77c915b429 100755 (executable)
@@ -591,7 +591,7 @@ test_expect_success 'cvs annotate' '
     cd cvswork &&
     GIT_CONFIG="$git_config" cvs annotate merge >../out &&
     sed -e "s/ .*//" ../out >../actual &&
-    for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
+    printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
     test_cmp ../expect ../actual
 '