Skip to content

Commit efe26b9

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

7 files changed

+14
-50
lines changed

t/t3005-ls-files-relative.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ test_expect_success 'ls-files with mixed levels' '
3939
test_expect_success 'ls-files -c' '
4040
(
4141
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 &&
4643
echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
4744
ls ../x* >expect.out &&
4845
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' '
5451
test_expect_success 'ls-files -o' '
5552
(
5653
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 &&
6155
echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
6256
ls ../y* >expect.out &&
6357
test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err &&

t/t3600-rm.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,7 @@ test_expect_success 'Resolving by removal is not a warning-worthy event' '
274274
git reset -q --hard &&
275275
test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
276276
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 &&
281278
git rm blob >msg 2>&1 &&
282279
test_i18ngrep ! "needs merge" msg &&
283280
test_must_fail git ls-files -s --error-unmatch blob

t/t4025-hunk-header.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@ test_expect_success setup '
1414
1515
(
1616
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 &&
2118
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
2620
) >file &&
2721
git add file &&
2822

t/t4125-apply-ws-fuzz.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ test_expect_success setup '
1010
git add file &&
1111
1212
# 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 &&
1714
1815
# patch-0 creates a whitespace broken file
1916
cat file-0 >file &&

t/t6416-recursive-corner-cases.sh

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@ test_expect_success 'setup basic criss-cross + rename with no modifications' '
2424
cd basic-rename &&
2525
2626
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 &&
3529
git add one two &&
3630
test_tick && git commit -m initial &&
3731
@@ -96,14 +90,8 @@ test_expect_success 'setup criss-cross + rename merges with basic modification'
9690
cd rename-modify &&
9791
9892
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 &&
10795
git add one two &&
10896
test_tick && git commit -m initial &&
10997
@@ -1588,10 +1576,7 @@ test_expect_success 'setup nested conflicts' '
15881576
cd nested_conflicts &&
15891577
15901578
# 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 &&
15951580
15961581
cp initial b_L1 &&
15971582
cp initial b_R1 &&
@@ -1777,10 +1762,7 @@ test_expect_success 'setup virtual merge base with nested conflicts' '
17771762
cd virtual_merge_base_has_nested_conflicts &&
17781763
17791764
# 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 &&
17841766
17851767
# Setup original commit
17861768
git add content &&

t/t7110-reset-merge.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_description='Tests for "git reset" with "--merge" and "--keep" options'
88
. ./test-lib.sh
99

1010
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 &&
1212
cat file1 >file2 &&
1313
git add file1 file2 &&
1414
test_tick &&

t/t9400-git-cvsserver-server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ test_expect_success 'cvs annotate' '
591591
cd cvswork &&
592592
GIT_CONFIG="$git_config" cvs annotate merge >../out &&
593593
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 &&
595595
test_cmp ../expect ../actual
596596
'
597597

0 commit comments

Comments
 (0)