t: use test_write_lines() instead of series of 'echo' commands
These tests employ a noisy subshell (with missing &&-chain) to feed input into Git commands or files: (echo a; echo b; echo c) | git some-command ... Simplify by taking advantage of test_write_lines(): test_write_lines a b c | git some-command ... Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Jul 1, 2018 at 20:23 UTC
0590ff26c406204281262c2753b3b92aa07f59c7
10 files changed
+61
-62
t/t0090-cache-tree.sh
+1
-1
@@ -156,7 +156,7 @@ test_expect_success PERL 'commit --interactive gives cache-tree on partial commi
156
return 44;
157
}
158
EOT
159
- (echo p; echo 1; echo; echo s; echo n; echo y; echo q) |
159
+ test_write_lines p 1 "" s n y q |
160
git commit --interactive -m foo &&
161
test_cache_tree
162
'
t/t1008-read-tree-overlay.sh
+1
-1
@@ -23,7 +23,7 @@ test_expect_success setup '
23
24
test_expect_success 'multi-read' '
25
read_tree_must_succeed initial master side &&
26
- (echo a; echo b/c) >expect &&
26
+ test_write_lines a b/c >expect &&
27
git ls-files >actual &&
28
test_cmp expect actual
29
'
t/t2016-checkout-patch.sh
+12
-12
@@ -20,33 +20,33 @@ test_expect_success PERL 'setup' '
20
21
test_expect_success PERL 'saying "n" does nothing' '
22
set_and_save_state dir/foo work head &&
23
- (echo n; echo n) | git checkout -p &&
23
+ test_write_lines n n | git checkout -p &&
24
verify_saved_state bar &&
25
verify_saved_state dir/foo
26
'
27
28
test_expect_success PERL 'git checkout -p' '
29
- (echo n; echo y) | git checkout -p &&
29
+ test_write_lines n y | git checkout -p &&
30
verify_saved_state bar &&
31
verify_state dir/foo head head
32
'
33
34
test_expect_success PERL 'git checkout -p with staged changes' '
35
set_state dir/foo work index &&
36
- (echo n; echo y) | git checkout -p &&
36
+ test_write_lines n y | git checkout -p &&
37
verify_saved_state bar &&
38
verify_state dir/foo index index
39
'
40
41
test_expect_success PERL 'git checkout -p HEAD with NO staged changes: abort' '
42
set_and_save_state dir/foo work head &&
43
- (echo n; echo y; echo n) | git checkout -p HEAD &&
43
+ test_write_lines n y n | git checkout -p HEAD &&
44
verify_saved_state bar &&
45
verify_saved_state dir/foo
46
'
47
48
test_expect_success PERL 'git checkout -p HEAD with NO staged changes: apply' '
49
- (echo n; echo y; echo y) | git checkout -p HEAD &&
49
+ test_write_lines n y y | git checkout -p HEAD &&
50
verify_saved_state bar &&
51
verify_state dir/foo head head
52
'
@@ -54,14 +54,14 @@ test_expect_success PERL 'git checkout -p HEAD with NO staged changes: apply' '
54
test_expect_success PERL 'git checkout -p HEAD with change already staged' '
55
set_state dir/foo index index &&
56
# the third n is to get out in case it mistakenly does not apply
57
- (echo n; echo y; echo n) | git checkout -p HEAD &&
57
+ test_write_lines n y n | git checkout -p HEAD &&
58
verify_saved_state bar &&
59
verify_state dir/foo head head
60
'
61
62
test_expect_success PERL 'git checkout -p HEAD^' '
63
# the third n is to get out in case it mistakenly does not apply
64
- (echo n; echo y; echo n) | git checkout -p HEAD^ &&
64
+ test_write_lines n y n | git checkout -p HEAD^ &&
65
verify_saved_state bar &&
66
verify_state dir/foo parent parent
67
'
@@ -69,7 +69,7 @@ test_expect_success PERL 'git checkout -p HEAD^' '
69
test_expect_success PERL 'git checkout -p handles deletion' '
70
set_state dir/foo work index &&
71
rm dir/foo &&
72
- (echo n; echo y) | git checkout -p &&
72
+ test_write_lines n y | git checkout -p &&
73
verify_saved_state bar &&
74
verify_state dir/foo index index
75
'
@@ -81,21 +81,21 @@ test_expect_success PERL 'git checkout -p handles deletion' '
81
82
test_expect_success PERL 'path limiting works: dir' '
83
set_state dir/foo work head &&
84
- (echo y; echo n) | git checkout -p dir &&
84
+ test_write_lines y n | git checkout -p dir &&
85
verify_saved_state bar &&
86
verify_state dir/foo head head
87
'
88
89
test_expect_success PERL 'path limiting works: -- dir' '
90
set_state dir/foo work head &&
91
- (echo y; echo n) | git checkout -p -- dir &&
91
+ test_write_lines y n | git checkout -p -- dir &&
92
verify_saved_state bar &&
93
verify_state dir/foo head head
94
'
95
96
test_expect_success PERL 'path limiting works: HEAD^ -- dir' '
97
# the third n is to get out in case it mistakenly does not apply
98
- (echo y; echo n; echo n) | git checkout -p HEAD^ -- dir &&
98
+ test_write_lines y n n | git checkout -p HEAD^ -- dir &&
99
verify_saved_state bar &&
100
verify_state dir/foo parent parent
101
'
@@ -103,7 +103,7 @@ test_expect_success PERL 'path limiting works: HEAD^ -- dir' '
103
test_expect_success PERL 'path limiting works: foo inside dir' '
104
set_state dir/foo work head &&
105
# the third n is to get out in case it mistakenly does not apply
106
- (echo y; echo n; echo n) | (cd dir && git checkout -p foo) &&
106
+ test_write_lines y n n | (cd dir && git checkout -p foo) &&
107
verify_saved_state bar &&
108
verify_state dir/foo head head
109
'
t/t3404-rebase-interactive.sh
+3
-3
@@ -509,7 +509,7 @@ test_expect_success 'interrupted squash works as expected' '
509
one=$(git rev-parse HEAD~3) &&
510
set_fake_editor &&
511
test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
512
- (echo one; echo two; echo four) > conflict &&
512
+ test_write_lines one two four > conflict &&
513
git add conflict &&
514
test_must_fail git rebase --continue &&
515
echo resolved > conflict &&
@@ -523,10 +523,10 @@ test_expect_success 'interrupted squash works as expected (case 2)' '
523
one=$(git rev-parse HEAD~3) &&
524
set_fake_editor &&
525
test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
526
- (echo one; echo four) > conflict &&
526
+ test_write_lines one four > conflict &&
527
git add conflict &&
528
test_must_fail git rebase --continue &&
529
- (echo one; echo two; echo four) > conflict &&
529
+ test_write_lines one two four > conflict &&
530
git add conflict &&
531
test_must_fail git rebase --continue &&
532
echo resolved > conflict &&
t/t3701-add-interactive.sh
+8
-8
@@ -46,13 +46,13 @@ test_expect_success 'setup expected' '
46
'
47
48
test_expect_success 'diff works (initial)' '
49
- (echo d; echo 1) | git add -i >output &&
49
+ test_write_lines d 1 | git add -i >output &&
50
sed -ne "/new file/,/content/p" <output >diff &&
51
diff_cmp expected diff
52
'
53
test_expect_success 'revert works (initial)' '
54
git add file &&
55
- (echo r; echo 1) | git add -i &&
55
+ test_write_lines r 1 | git add -i &&
56
git ls-files >output &&
57
! grep . output
58
'
@@ -83,13 +83,13 @@ test_expect_success 'setup expected' '
83
'
84
85
test_expect_success 'diff works (commit)' '
86
- (echo d; echo 1) | git add -i >output &&
86
+ test_write_lines d 1 | git add -i >output &&
87
sed -ne "/^index/,/content/p" <output >diff &&
88
diff_cmp expected diff
89
'
90
test_expect_success 'revert works (commit)' '
91
git add file &&
92
- (echo r; echo 1) | git add -i &&
92
+ test_write_lines r 1 | git add -i &&
93
git add -i </dev/null >output &&
94
grep "unchanged *+3/-0 file" output
95
'
@@ -102,7 +102,7 @@ test_expect_success 'setup expected' '
102
103
test_expect_success 'dummy edit works' '
104
test_set_editor : &&
105
- (echo e; echo a) | git add -p &&
105
+ test_write_lines e a | git add -p &&
106
git diff > diff &&
107
diff_cmp expected diff
108
'
@@ -127,7 +127,7 @@ test_expect_success 'setup fake editor' '
127
128
test_expect_success 'bad edit rejected' '
129
git reset &&
130
- (echo e; echo n; echo d) | git add -p >output &&
130
+ test_write_lines e n d | git add -p >output &&
131
grep "hunk does not apply" output
132
'
133
@@ -140,7 +140,7 @@ test_expect_success 'setup patch' '
140
141
test_expect_success 'garbage edit rejected' '
142
git reset &&
143
- (echo e; echo n; echo d) | git add -p >output &&
143
+ test_write_lines e n d | git add -p >output &&
144
grep "hunk does not apply" output
145
'
146
@@ -170,7 +170,7 @@ test_expect_success 'setup expected' '
170
'
171
172
test_expect_success 'real edit works' '
173
- (echo e; echo n; echo d) | git add -p &&
173
+ test_write_lines e n d | git add -p &&
174
git diff >output &&
175
diff_cmp expected output
176
'
t/t3904-stash-patch.sh
+4
-4
@@ -29,14 +29,14 @@ test_expect_success 'setup' '
29
test_expect_success 'saying "n" does nothing' '
30
set_state HEAD HEADfile_work HEADfile_index &&
31
set_state dir/foo work index &&
32
- (echo n; echo n; echo n) | test_must_fail git stash save -p &&
32
+ test_write_lines n n n | test_must_fail git stash save -p &&
33
verify_state HEAD HEADfile_work HEADfile_index &&
34
verify_saved_state bar &&
35
verify_state dir/foo work index
36
'
37
38
test_expect_success 'git stash -p' '
39
- (echo y; echo n; echo y) | git stash save -p &&
39
+ test_write_lines y n y | git stash save -p &&
40
verify_state HEAD committed HEADfile_index &&
41
verify_saved_state bar &&
42
verify_state dir/foo head index &&
@@ -51,7 +51,7 @@ test_expect_success 'git stash -p --no-keep-index' '
51
set_state HEAD HEADfile_work HEADfile_index &&
52
set_state bar bar_work bar_index &&
53
set_state dir/foo work index &&
54
- (echo y; echo n; echo y) | git stash save -p --no-keep-index &&
54
+ test_write_lines y n y | git stash save -p --no-keep-index &&
55
verify_state HEAD committed committed &&
56
verify_state bar bar_work dummy &&
57
verify_state dir/foo head head &&
@@ -66,7 +66,7 @@ test_expect_success 'git stash --no-keep-index -p' '
66
set_state HEAD HEADfile_work HEADfile_index &&
67
set_state bar bar_work bar_index &&
68
set_state dir/foo work index &&
69
- (echo y; echo n; echo y) | git stash save --no-keep-index -p &&
69
+ test_write_lines y n y | git stash save --no-keep-index -p &&
70
verify_state HEAD committed committed &&
71
verify_state dir/foo head head &&
72
verify_state bar bar_work dummy &&
t/t7105-reset-patch.sh
+6
-6
@@ -19,20 +19,20 @@ test_expect_success PERL 'setup' '
19
20
test_expect_success PERL 'saying "n" does nothing' '
21
set_and_save_state dir/foo work work &&
22
- (echo n; echo n) | git reset -p &&
22
+ test_write_lines n n | git reset -p &&
23
verify_saved_state dir/foo &&
24
verify_saved_state bar
25
'
26
27
test_expect_success PERL 'git reset -p' '
28
- (echo n; echo y) | git reset -p >output &&
28
+ test_write_lines n y | git reset -p >output &&
29
verify_state dir/foo work head &&
30
verify_saved_state bar &&
31
test_i18ngrep "Unstage" output
32
'
33
34
test_expect_success PERL 'git reset -p HEAD^' '
35
- (echo n; echo y) | git reset -p HEAD^ >output &&
35
+ test_write_lines n y | git reset -p HEAD^ >output &&
36
verify_state dir/foo work parent &&
37
verify_saved_state bar &&
38
test_i18ngrep "Apply" output
@@ -45,20 +45,20 @@ test_expect_success PERL 'git reset -p HEAD^' '
45
46
test_expect_success PERL 'git reset -p dir' '
47
set_state dir/foo work work &&
48
- (echo y; echo n) | git reset -p dir &&
48
+ test_write_lines y n | git reset -p dir &&
49
verify_state dir/foo work head &&
50
verify_saved_state bar
51
'
52
53
test_expect_success PERL 'git reset -p -- foo (inside dir)' '
54
set_state dir/foo work work &&
55
- (echo y; echo n) | (cd dir && git reset -p -- foo) &&
55
+ test_write_lines y n | (cd dir && git reset -p -- foo) &&
56
verify_state dir/foo work head &&
57
verify_saved_state bar
58
'
59
60
test_expect_success PERL 'git reset -p HEAD^ -- dir' '
61
- (echo y; echo n) | git reset -p HEAD^ -- dir &&
61
+ test_write_lines y n | git reset -p HEAD^ -- dir &&
62
verify_state dir/foo work parent &&
63
verify_saved_state bar
64
'
t/t7301-clean-interactive.sh
+20
-21
@@ -107,7 +107,7 @@ test_expect_success 'git clean -id (filter all)' '
107
mkdir -p build docs &&
108
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
109
docs/manual.txt obj.o build/lib.so &&
110
- (echo f; echo "*"; echo; echo c) | \
110
+ test_write_lines f "*" "" c |
111
git clean -id &&
112
test -f Makefile &&
113
test -f README &&
@@ -129,7 +129,7 @@ test_expect_success 'git clean -id (filter patterns)' '
129
mkdir -p build docs &&
130
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
131
docs/manual.txt obj.o build/lib.so &&
132
- (echo f; echo "part3.* *.out"; echo; echo c) | \
132
+ test_write_lines f "part3.* *.out" "" c |
133
git clean -id &&
134
test -f Makefile &&
135
test -f README &&
@@ -151,7 +151,7 @@ test_expect_success 'git clean -id (filter patterns 2)' '
151
mkdir -p build docs &&
152
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
153
docs/manual.txt obj.o build/lib.so &&
154
- (echo f; echo "* !*.out"; echo; echo c) | \
154
+ test_write_lines f "* !*.out" "" c |
155
git clean -id &&
156
test -f Makefile &&
157
test -f README &&
@@ -173,7 +173,7 @@ test_expect_success 'git clean -id (select - all)' '
173
mkdir -p build docs &&
174
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
175
docs/manual.txt obj.o build/lib.so &&
176
- (echo s; echo "*"; echo; echo c) | \
176
+ test_write_lines s "*" "" c |
177
git clean -id &&
178
test -f Makefile &&
179
test -f README &&
@@ -195,7 +195,7 @@ test_expect_success 'git clean -id (select - none)' '
195
mkdir -p build docs &&
196
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
197
docs/manual.txt obj.o build/lib.so &&
198
- (echo s; echo; echo c) | \
198
+ test_write_lines s "" c |
199
git clean -id &&
200
test -f Makefile &&
201
test -f README &&
@@ -217,7 +217,7 @@ test_expect_success 'git clean -id (select - number)' '
217
mkdir -p build docs &&
218
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
219
docs/manual.txt obj.o build/lib.so &&
220
- (echo s; echo 3; echo; echo c) | \
220
+ test_write_lines s 3 "" c |
221
git clean -id &&
222
test -f Makefile &&
223
test -f README &&
@@ -239,7 +239,7 @@ test_expect_success 'git clean -id (select - number 2)' '
239
mkdir -p build docs &&
240
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
241
docs/manual.txt obj.o build/lib.so &&
242
- (echo s; echo 2 3; echo 5; echo; echo c) | \
242
+ test_write_lines s "2 3" 5 "" c |
243
git clean -id &&
244
test -f Makefile &&
245
test -f README &&
@@ -261,7 +261,7 @@ test_expect_success 'git clean -id (select - number 3)' '
261
mkdir -p build docs &&
262
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
263
docs/manual.txt obj.o build/lib.so &&
264
- (echo s; echo 3,4 5; echo; echo c) | \
264
+ test_write_lines s "3,4 5" "" c |
265
git clean -id &&
266
test -f Makefile &&
267
test -f README &&
@@ -282,7 +282,7 @@ test_expect_success 'git clean -id (select - filenames)' '
282
283
mkdir -p build docs &&
284
touch a.out foo.txt bar.txt baz.txt &&
285
- (echo s; echo a.out fo ba bar; echo; echo c) | \
285
+ test_write_lines s "a.out fo ba bar" "" c |
286
git clean -id &&
287
test -f Makefile &&
288
test ! -f a.out &&
@@ -298,7 +298,7 @@ test_expect_success 'git clean -id (select - range)' '
298
mkdir -p build docs &&
299
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
300
docs/manual.txt obj.o build/lib.so &&
301
- (echo s; echo 1,3-4; echo 2; echo; echo c) | \
301
+ test_write_lines s "1,3-4" 2 "" c |
302
git clean -id &&
303
test -f Makefile &&
304
test -f README &&
@@ -320,7 +320,7 @@ test_expect_success 'git clean -id (select - range 2)' '
320
mkdir -p build docs &&
321
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
322
docs/manual.txt obj.o build/lib.so &&
323
- (echo s; echo 4- 1; echo; echo c) | \
323
+ test_write_lines s "4- 1" "" c |
324
git clean -id &&
325
test -f Makefile &&
326
test -f README &&
@@ -342,7 +342,7 @@ test_expect_success 'git clean -id (inverse select)' '
342
mkdir -p build docs &&
343
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
344
docs/manual.txt obj.o build/lib.so &&
345
- (echo s; echo "*"; echo -5- 1 -2; echo; echo c) | \
345
+ test_write_lines s "*" "-5- 1 -2" "" c |
346
git clean -id &&
347
test -f Makefile &&
348
test -f README &&
@@ -364,7 +364,7 @@ test_expect_success 'git clean -id (ask)' '
364
mkdir -p build docs &&
365
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
366
docs/manual.txt obj.o build/lib.so &&
367
- (echo a; echo Y; echo y; echo no; echo yes; echo bad; echo) | \
367
+ test_write_lines a Y y no yes bad "" |
368
git clean -id &&
369
test -f Makefile &&
370
test -f README &&
@@ -386,7 +386,7 @@ test_expect_success 'git clean -id (ask - Ctrl+D)' '
386
mkdir -p build docs &&
387
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
388
docs/manual.txt obj.o build/lib.so &&
389
- (echo a; echo Y; echo no; echo yes; echo "\04") | \
389
+ test_write_lines a Y no yes "\04" |
390
git clean -id &&
391
test -f Makefile &&
392
test -f README &&
@@ -408,8 +408,8 @@ test_expect_success 'git clean -id with prefix and path (filter)' '
408
mkdir -p build docs &&
409
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
410
docs/manual.txt obj.o build/lib.so &&
411
- (cd build/ && \
412
- (echo f; echo "docs"; echo "*.h"; echo ; echo c) | \
411
+ (cd build/ &&
412
+ test_write_lines f docs "*.h" "" c |
413
git clean -id ..) &&
414
test -f Makefile &&
415
test -f README &&
@@ -431,9 +431,8 @@ test_expect_success 'git clean -id with prefix and path (select by name)' '
431
mkdir -p build docs &&
432
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
433
docs/manual.txt obj.o build/lib.so &&
434
- (cd build/ && \
435
- (echo s; echo "../docs/"; echo "../src/part3.c"; \
436
- echo "../src/part4.c"; echo; echo c) | \
434
+ (cd build/ &&
435
+ test_write_lines s ../docs/ ../src/part3.c ../src/part4.c "" c |
436
git clean -id ..) &&
437
test -f Makefile &&
438
test -f README &&
@@ -455,8 +454,8 @@ test_expect_success 'git clean -id with prefix and path (ask)' '
454
mkdir -p build docs &&
455
touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
456
docs/manual.txt obj.o build/lib.so &&
458
- (cd build/ && \
459
- (echo a; echo Y; echo y; echo no; echo yes; echo bad; echo) | \
457
+ (cd build/ &&
458
+ test_write_lines a Y y no yes bad "" |
459
git clean -id ..) &&
460
test -f Makefile &&
461
test -f README &&
t/t7501-commit.sh
+2
-2
@@ -47,7 +47,7 @@ test_expect_success 'paths and -a do not mix' '
47
test_expect_success PERL 'can use paths with --interactive' '
48
echo bong-o-bong >file &&
49
# 2: update, 1:st path, that is all, 7: quit
50
- ( echo 2; echo 1; echo; echo 7 ) |
50
+ test_write_lines 2 1 "" 7 |
51
git commit -m foo --interactive file &&
52
git reset --hard HEAD^
53
'
@@ -293,7 +293,7 @@ test_expect_success PERL 'interactive add' '
293
test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
294
echo zoo >file &&
295
test_must_fail git diff --exit-code >diff1 &&
296
- (echo u ; echo "*" ; echo q) |
296
+ test_write_lines u "*" q |
297
(
298
EDITOR=: &&
299
export EDITOR &&
t/t7610-mergetool.sh
+4
-4
@@ -57,18 +57,18 @@ test_expect_success 'setup' '
57
58
git checkout -b delete-base branch1 &&
59
mkdir -p a/a &&
60
- (echo one; echo two; echo 3; echo 4) >a/a/file.txt &&
60
+ test_write_lines one two 3 4 >a/a/file.txt &&
61
git add a/a/file.txt &&
62
git commit -m"base file" &&
63
git checkout -b move-to-b delete-base &&
64
mkdir -p b/b &&
65
git mv a/a/file.txt b/b/file.txt &&
66
- (echo one; echo two; echo 4) >b/b/file.txt &&
66
+ test_write_lines one two 4 >b/b/file.txt &&
67
git commit -a -m"move to b" &&
68
git checkout -b move-to-c delete-base &&
69
mkdir -p c/c &&
70
git mv a/a/file.txt c/c/file.txt &&
71
- (echo one; echo two; echo 3) >c/c/file.txt &&
71
+ test_write_lines one two 3 >c/c/file.txt &&
72
git commit -a -m"move to c" &&
73
74
git checkout -b stash1 master &&
@@ -349,7 +349,7 @@ test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
349
git checkout -b test$test_count move-to-c &&
350
test_config mergetool.keepTemporaries true &&
351
test_must_fail git merge move-to-b &&
352
- ! (echo a; echo n) | git mergetool a/a/file.txt &&
352
+ ! test_write_lines a n | git mergetool a/a/file.txt &&
353
test -d a/a &&
354
cat >expect <<-\EOF &&
355
file_BASE_.txt