tests: simplify by dropping unnecessary `for` loops

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>

Eric Sunshine committed Dec 9, 2021 at 00:11 UTC efe26b9ee09d53dda0f36d0ea20cb245b934f216
7 files changed +14 -50
t/t3005-ls-files-relative.sh
+2 -8
@@ -39,10 +39,7 @@ test_expect_success 'ls-files with mixed levels' '
39 test_expect_success 'ls-files -c' '
40 (
41 cd top/sub &&
42 - for f in ../y*
43 - do
44 - echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git"
45 - done >expect.err &&
42 + printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../y* >expect.err &&
43 echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
44 ls ../x* >expect.out &&
45 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' '
51 test_expect_success 'ls-files -o' '
52 (
53 cd top/sub &&
57 - for f in ../x*
58 - do
59 - echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git"
60 - done >expect.err &&
54 + printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../x* >expect.err &&
55 echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
56 ls ../y* >expect.out &&
57 test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err &&
t/t3600-rm.sh
+1 -4
@@ -274,10 +274,7 @@ test_expect_success 'Resolving by removal is not a warning-worthy event' '
274 git reset -q --hard &&
275 test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
276 blob=$(echo blob | git hash-object -w --stdin) &&
277 - for stage in 1 2 3
278 - do
279 - echo "100644 $blob $stage blob"
280 - done | git update-index --index-info &&
277 + printf "100644 $blob %d\tblob\n" 1 2 3 | git update-index --index-info &&
278 git rm blob >msg 2>&1 &&
279 test_i18ngrep ! "needs merge" msg &&
280 test_must_fail git ls-files -s --error-unmatch blob
t/t4025-hunk-header.sh
+2 -8
@@ -14,15 +14,9 @@ test_expect_success setup '
14
15 (
16 echo "A $NS" &&
17 - for c in B C D E F G H I J K
18 - do
19 - echo " $c"
20 - done &&
17 + printf " %s\n" B C D E F G H I J K &&
18 echo "L $NS" &&
22 - for c in M N O P Q R S T U V
23 - do
24 - echo " $c"
25 - done
19 + printf " %s\n" M N O P Q R S T U V
20 ) >file &&
21 git add file &&
22
t/t4125-apply-ws-fuzz.sh
+1 -4
@@ -10,10 +10,7 @@ test_expect_success setup '
10 git add file &&
11
12 # file-0 is full of whitespace breakages
13 - for l in a bb c d eeee f ggg h
14 - do
15 - echo "$l "
16 - done >file-0 &&
13 + printf "%s \n" a bb c d eeee f ggg h >file-0 &&
14
15 # patch-0 creates a whitespace broken file
16 cat file-0 >file &&
t/t6416-recursive-corner-cases.sh
+6 -24
@@ -24,14 +24,8 @@ test_expect_success 'setup basic criss-cross + rename with no modifications' '
24 cd basic-rename &&
25
26 ten="0 1 2 3 4 5 6 7 8 9" &&
27 - for i in $ten
28 - do
29 - echo line $i in a sample file
30 - done >one &&
31 - for i in $ten
32 - do
33 - echo line $i in another sample file
34 - done >two &&
27 + printf "line %d in a sample file\n" $ten >one &&
28 + printf "line %d in another sample file\n" $ten >two &&
29 git add one two &&
30 test_tick && git commit -m initial &&
31
@@ -96,14 +90,8 @@ test_expect_success 'setup criss-cross + rename merges with basic modification'
90 cd rename-modify &&
91
92 ten="0 1 2 3 4 5 6 7 8 9" &&
99 - for i in $ten
100 - do
101 - echo line $i in a sample file
102 - done >one &&
103 - for i in $ten
104 - do
105 - echo line $i in another sample file
106 - done >two &&
93 + printf "line %d in a sample file\n" $ten >one &&
94 + printf "line %d in another sample file\n" $ten >two &&
95 git add one two &&
96 test_tick && git commit -m initial &&
97
@@ -1588,10 +1576,7 @@ test_expect_success 'setup nested conflicts' '
1576 cd nested_conflicts &&
1577
1578 # Create some related files now
1591 - for i in $(test_seq 1 10)
1592 - do
1593 - echo Random base content line $i
1594 - done >initial &&
1579 + printf "Random base content line %d\n" $(test_seq 1 10) >initial &&
1580
1581 cp initial b_L1 &&
1582 cp initial b_R1 &&
@@ -1777,10 +1762,7 @@ test_expect_success 'setup virtual merge base with nested conflicts' '
1762 cd virtual_merge_base_has_nested_conflicts &&
1763
1764 # Create some related files now
1780 - for i in $(test_seq 1 10)
1781 - do
1782 - echo Random base content line $i
1783 - done >content &&
1765 + printf "Random base content line %d\n" $(test_seq 1 10) >content &&
1766
1767 # Setup original commit
1768 git add content &&
t/t7110-reset-merge.sh
+1 -1
@@ -8,7 +8,7 @@ test_description='Tests for "git reset" with "--merge" and "--keep" options'
8 . ./test-lib.sh
9
10 test_expect_success setup '
11 - for i in 1 2 3; do echo line $i; done >file1 &&
11 + printf "line %d\n" 1 2 3 >file1 &&
12 cat file1 >file2 &&
13 git add file1 file2 &&
14 test_tick &&
t/t9400-git-cvsserver-server.sh
+1 -1
@@ -591,7 +591,7 @@ test_expect_success 'cvs annotate' '
591 cd cvswork &&
592 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
593 sed -e "s/ .*//" ../out >../actual &&
594 - for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
594 + printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
595 test_cmp ../expect ../actual
596 '
597