Skip to content

Commit 0849541

Browse files
sunshinecogitster
authored andcommitted
tests: use test_write_lines() to generate line-oriented output
Take advantage of test_write_lines() to generate line-oriented output rather than using for-loops or a series of `echo` commands. Not only is test_write_lines() a natural fit for such a task, but there is less opportunity for a broken &&-chain. Signed-off-by: Eric Sunshine <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 020b813 commit 0849541

26 files changed

+106
-170
lines changed

t/t0020-crlf.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ test_expect_success setup '
2222
2323
git config core.autocrlf false &&
2424
25-
for w in Hello world how are you; do echo $w; done >one &&
25+
test_write_lines Hello world how are you >one &&
2626
mkdir dir &&
27-
for w in I am very very fine thank you; do echo $w; done >dir/two &&
28-
for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
27+
test_write_lines I am very very fine thank you >dir/two &&
28+
test_write_lines Oh here is NULQin text here | q_to_nul >three &&
2929
git add . &&
3030
3131
git commit -m initial &&
@@ -35,7 +35,7 @@ test_expect_success setup '
3535
two=$(git rev-parse HEAD:dir/two) &&
3636
three=$(git rev-parse HEAD:three) &&
3737
38-
for w in Some extra lines here; do echo $w; done >>one &&
38+
test_write_lines Some extra lines here >>one &&
3939
git diff >patch.file &&
4040
patched=$(git hash-object --stdin <one) &&
4141
git read-tree --reset -u HEAD
@@ -46,7 +46,7 @@ test_expect_success 'safecrlf: autocrlf=input, all CRLF' '
4646
git config core.autocrlf input &&
4747
git config core.safecrlf true &&
4848
49-
for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
49+
test_write_lines I am all CRLF | append_cr >allcrlf &&
5050
test_must_fail git add allcrlf
5151
'
5252

@@ -55,7 +55,7 @@ test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' '
5555
git config core.autocrlf input &&
5656
git config core.safecrlf true &&
5757
58-
for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
58+
test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
5959
test_must_fail git add mixed
6060
'
6161

@@ -64,7 +64,7 @@ test_expect_success 'safecrlf: autocrlf=true, all LF' '
6464
git config core.autocrlf true &&
6565
git config core.safecrlf true &&
6666
67-
for w in I am all LF; do echo $w; done >alllf &&
67+
test_write_lines I am all LF >alllf &&
6868
test_must_fail git add alllf
6969
'
7070

@@ -73,7 +73,7 @@ test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' '
7373
git config core.autocrlf true &&
7474
git config core.safecrlf true &&
7575
76-
for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
76+
test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
7777
test_must_fail git add mixed
7878
'
7979

@@ -82,10 +82,10 @@ test_expect_success 'safecrlf: print warning only once' '
8282
git config core.autocrlf input &&
8383
git config core.safecrlf warn &&
8484
85-
for w in I am all LF; do echo $w; done >doublewarn &&
85+
test_write_lines I am all LF >doublewarn &&
8686
git add doublewarn &&
8787
git commit -m "nowarn" &&
88-
for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn &&
88+
test_write_lines Oh here is CRLFQ in text | q_to_cr >doublewarn &&
8989
git add doublewarn 2>err &&
9090
grep "CRLF will be replaced by LF" err >err.warnings &&
9191
test_line_count = 1 err.warnings
@@ -103,7 +103,7 @@ test_expect_success 'safecrlf: no warning with safecrlf=false' '
103103
git config core.autocrlf input &&
104104
git config core.safecrlf false &&
105105
106-
for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
106+
test_write_lines I am all CRLF | append_cr >allcrlf &&
107107
git add allcrlf 2>err &&
108108
test_must_be_empty err
109109
'
@@ -351,9 +351,9 @@ test_expect_success 'setting up for new autocrlf tests' '
351351
git config core.autocrlf false &&
352352
git config core.safecrlf false &&
353353
rm -rf .????* * &&
354-
for w in I am all LF; do echo $w; done >alllf &&
355-
for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
356-
for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
354+
test_write_lines I am all LF >alllf &&
355+
test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
356+
test_write_lines I am all CRLF | append_cr >allcrlf &&
357357
git add -A . &&
358358
git commit -m "alllf, allcrlf and mixed only" &&
359359
git tag -a -m "message" autocrlf-checkpoint

t/t0026-eol-config.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ test_expect_success setup '
1515
1616
echo "one text" > .gitattributes &&
1717
18-
for w in Hello world how are you; do echo $w; done >one &&
19-
for w in I am very very fine thank you; do echo $w; done >two &&
18+
test_write_lines Hello world how are you >one &&
19+
test_write_lines I am very very fine thank you >two &&
2020
git add . &&
2121
2222
git commit -m initial &&

t/t1020-subdirectory.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ test_description='Try various core-level commands in subdirectory.
1111

1212
test_expect_success setup '
1313
long="a b c d e f g h i j k l m n o p q r s t u v w x y z" &&
14-
for c in $long; do echo $c; done >one &&
14+
test_write_lines $long >one &&
1515
mkdir dir &&
16-
for c in x y z $long a b c; do echo $c; done >dir/two &&
16+
test_write_lines x y z $long a b c >dir/two &&
1717
cp one original.one &&
1818
cp dir/two original.two
1919
'

t/t1512-rev-parse-disambiguation.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ fi
3434
test_expect_success 'blob and tree' '
3535
test_tick &&
3636
(
37-
for i in 0 1 2 3 4 5 6 7 8 9
38-
do
39-
echo $i
40-
done &&
37+
test_write_lines 0 1 2 3 4 5 6 7 8 9 &&
4138
echo &&
4239
echo b1rwzyc3
4340
) >a0blgqsjc &&
@@ -204,10 +201,7 @@ test_expect_success 'more history' '
204201
git checkout v1.0.0^0 &&
205202
git mv a0blgqsjc f5518nwu &&
206203
207-
for i in h62xsjeu j08bekfvt kg7xflhm
208-
do
209-
echo $i
210-
done >>f5518nwu &&
204+
test_write_lines h62xsjeu j08bekfvt kg7xflhm >>f5518nwu &&
211205
git add f5518nwu &&
212206
213207
test_tick &&

t/t2103-update-index-ignore-missing.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test_expect_success basics '
2323
test_cmp expect actual &&
2424
2525
git update-index --add one two three &&
26-
for i in one three two; do echo $i; done >expect &&
26+
test_write_lines one three two >expect &&
2727
git ls-files >actual &&
2828
test_cmp expect actual &&
2929

t/t3417-rebase-whitespace-fix.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ test_expect_success 'at beginning of file' '
115115
git config core.whitespace "blank-at-eol" &&
116116
cp beginning file &&
117117
git commit -m beginning file &&
118-
for i in 1 2 3 4 5; do
119-
echo $i
120-
done >> file &&
118+
test_write_lines 1 2 3 4 5 >>file &&
121119
git commit -m more file &&
122120
git rebase --whitespace=fix HEAD^^ &&
123121
test_cmp expect-beginning file

t/t4013-diff-various.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ test_expect_success setup '
1919
2020
mkdir dir &&
2121
mkdir dir2 &&
22-
for i in 1 2 3; do echo $i; done >file0 &&
23-
for i in A B; do echo $i; done >dir/sub &&
22+
test_write_lines 1 2 3 >file0 &&
23+
test_write_lines A B >dir/sub &&
2424
cat file0 >file2 &&
2525
git add file0 file2 dir/sub &&
2626
git commit -m Initial &&
@@ -32,8 +32,8 @@ test_expect_success setup '
3232
GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
3333
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
3434
35-
for i in 4 5 6; do echo $i; done >>file0 &&
36-
for i in C D; do echo $i; done >>dir/sub &&
35+
test_write_lines 4 5 6 >>file0 &&
36+
test_write_lines C D >>dir/sub &&
3737
rm -f file2 &&
3838
git update-index --remove file0 file2 dir/sub &&
3939
git commit -m "Second${LF}${LF}This is the second commit." &&
@@ -42,9 +42,9 @@ test_expect_success setup '
4242
GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
4343
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
4444
45-
for i in A B C; do echo $i; done >file1 &&
45+
test_write_lines A B C >file1 &&
4646
git add file1 &&
47-
for i in E F; do echo $i; done >>dir/sub &&
47+
test_write_lines E F >>dir/sub &&
4848
git update-index dir/sub &&
4949
git commit -m Third &&
5050
@@ -53,8 +53,8 @@ test_expect_success setup '
5353
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
5454
5555
git checkout side &&
56-
for i in A B C; do echo $i; done >>file0 &&
57-
for i in 1 2; do echo $i; done >>dir/sub &&
56+
test_write_lines A B C >>file0 &&
57+
test_write_lines 1 2 >>dir/sub &&
5858
cat dir/sub >file3 &&
5959
git add file3 &&
6060
git update-index file0 dir/sub &&
@@ -71,8 +71,8 @@ test_expect_success setup '
7171
GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
7272
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
7373
74-
for i in A B C; do echo $i; done >>file0 &&
75-
for i in 1 2; do echo $i; done >>dir/sub &&
74+
test_write_lines A B C >>file0 &&
75+
test_write_lines 1 2 >>dir/sub &&
7676
git update-index file0 dir/sub &&
7777
7878
mkdir dir3 &&
@@ -86,7 +86,7 @@ test_expect_success setup '
8686
GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
8787
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
8888
git checkout -b rearrange initial &&
89-
for i in B A; do echo $i; done >dir/sub &&
89+
test_write_lines B A >dir/sub &&
9090
git add dir/sub &&
9191
git commit -m "Rearranged lines in dir/sub" &&
9292
git checkout master &&

t/t4014-format-patch.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1212
. "$TEST_DIRECTORY"/lib-terminal.sh
1313

1414
test_expect_success setup '
15-
for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
15+
test_write_lines 1 2 3 4 5 6 7 8 9 10 >file &&
1616
cat file >elif &&
1717
git add file elif &&
1818
test_tick &&
1919
git commit -m Initial &&
2020
git checkout -b side &&
2121
22-
for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
22+
test_write_lines 1 2 5 6 A B C 7 8 9 10 >file &&
2323
test_chmod +x elif &&
2424
test_tick &&
2525
git commit -m "Side changes #1" &&
2626
27-
for i in D E F; do echo "$i"; done >>file &&
27+
test_write_lines D E F >>file &&
2828
git update-index file &&
2929
test_tick &&
3030
git commit -m "Side changes #2" &&
3131
git tag C2 &&
3232
33-
for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
33+
test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file &&
3434
git update-index file &&
3535
test_tick &&
3636
git commit -m "Side changes #3 with \\n backslash-n in it." &&
@@ -43,18 +43,18 @@ test_expect_success setup '
4343
4444
git checkout side &&
4545
git checkout -b patchid &&
46-
for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file2 &&
47-
for i in 1 2 3 A 4 B C 7 8 9 10 D E F 5 6; do echo "$i"; done >file3 &&
48-
for i in 8 9 10; do echo "$i"; done >file &&
46+
test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file2 &&
47+
test_write_lines 1 2 3 A 4 B C 7 8 9 10 D E F 5 6 >file3 &&
48+
test_write_lines 8 9 10 >file &&
4949
git add file file2 file3 &&
5050
test_tick &&
5151
git commit -m "patchid 1" &&
52-
for i in 4 A B 7 8 9 10; do echo "$i"; done >file2 &&
53-
for i in 8 9 10 5 6; do echo "$i"; done >file3 &&
52+
test_write_lines 4 A B 7 8 9 10 >file2 &&
53+
test_write_lines 8 9 10 5 6 >file3 &&
5454
git add file2 file3 &&
5555
test_tick &&
5656
git commit -m "patchid 2" &&
57-
for i in 10 5 6; do echo "$i"; done >file &&
57+
test_write_lines 10 5 6 >file &&
5858
git add file &&
5959
test_tick &&
6060
git commit -m "patchid 3" &&
@@ -653,7 +653,7 @@ test_expect_success 'excessive subject' '
653653
git checkout side &&
654654
before=$(git hash-object file) &&
655655
before=$(git rev-parse --short $before) &&
656-
for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
656+
test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >>file &&
657657
after=$(git hash-object file) &&
658658
after=$(git rev-parse --short $after) &&
659659
git update-index file &&
@@ -1086,7 +1086,7 @@ test_expect_success TTY 'format-patch --stdout paginates' '
10861086
test_expect_success 'format-patch handles multi-line subjects' '
10871087
rm -rf patches/ &&
10881088
echo content >>file &&
1089-
for i in one two three; do echo $i; done >msg &&
1089+
test_write_lines one two three >msg &&
10901090
git add file &&
10911091
git commit -F msg &&
10921092
git format-patch -o patches -1 &&
@@ -1098,7 +1098,7 @@ test_expect_success 'format-patch handles multi-line subjects' '
10981098
test_expect_success 'format-patch handles multi-line encoded subjects' '
10991099
rm -rf patches/ &&
11001100
echo content >>file &&
1101-
for i in en två tre; do echo $i; done >msg &&
1101+
test_write_lines en två tre >msg &&
11021102
git add file &&
11031103
git commit -F msg &&
11041104
git format-patch -o patches -1 &&

t/t4019-diff-wserror.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ test_expect_success 'do not color trailing cr in context' '
287287
'
288288

289289
test_expect_success 'color new trailing blank lines' '
290-
{ echo a; echo b; echo; echo; } >x &&
290+
test_write_lines a b "" "" >x &&
291291
git add x &&
292-
{ echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
292+
test_write_lines a "" "" "" c "" "" "" "" >x &&
293293
git diff --color x >output &&
294294
cnt=$($grep_a "${blue_grep}" output | wc -l) &&
295295
test $cnt = 2

t/t4105-apply-fuzz.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@ dotest () {
1515

1616
test_expect_success setup '
1717
18-
for i in 1 2 3 4 5 6 7 8 9 10 11 12
19-
do
20-
echo $i
21-
done >file &&
18+
test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 >file &&
2219
git update-index --add file &&
23-
for i in 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12
24-
do
25-
echo $i
26-
done >file &&
20+
test_write_lines 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12 >file &&
2721
cat file >expect &&
2822
git diff >O0.diff &&
2923

0 commit comments

Comments
 (0)