completion: consolidate test_completion*() tests
No need to have two versions; if a second argument is specified, use that, otherwise use stdin. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Nov 11, 2012 at 15:35 UTC
2fbaf81381f4c80b5d8a97277374426f019fbc4a
1 file changed
+14
-17
t/t9902-completion.sh
+14
-17
@@ -60,19 +60,16 @@ run_completion ()
60
# 2: expected completion
61
test_completion ()
62
{
63
- test $# -gt 1 && echo "$2" > expected
63
+ if test $# -gt 1
64
+ then
65
+ printf '%s\n' "$2" >expected
66
+ else
67
+ sed -e 's/Z$//' >expected
68
+ fi &&
69
run_completion "$1" &&
70
test_cmp expected out
71
}
72
68
-# Like test_completion, but reads expectation from stdin,
69
-# which is convenient when it is multiline.
70
-test_completion_long ()
71
-{
72
- sed -e 's/Z$//' >expected &&
73
- test_completion "$1"
74
-}
75
-
73
newline=$'\n'
74
75
test_expect_success '__gitcomp - trailing space - options' '
@@ -172,7 +169,7 @@ test_expect_success 'basic' '
169
'
170
171
test_expect_success 'double dash "git" itself' '
175
- test_completion_long "git --" <<-\EOF
172
+ test_completion "git --" <<-\EOF
173
--paginate Z
174
--no-pager Z
175
--git-dir=
@@ -190,7 +187,7 @@ test_expect_success 'double dash "git" itself' '
187
'
188
189
test_expect_success 'double dash "git checkout"' '
193
- test_completion_long "git checkout --" <<-\EOF
190
+ test_completion "git checkout --" <<-\EOF
191
--quiet Z
192
--ours Z
193
--theirs Z
@@ -206,7 +203,7 @@ test_expect_success 'double dash "git checkout"' '
203
test_expect_success 'general options' '
204
test_completion "git --ver" "--version " &&
205
test_completion "git --hel" "--help " &&
209
- test_completion_long "git --exe" <<-\EOF &&
206
+ test_completion "git --exe" <<-\EOF &&
207
--exec-path Z
208
--exec-path=
209
EOF
@@ -247,7 +244,7 @@ test_expect_success 'setup for ref completion' '
244
'
245
246
test_expect_success 'checkout completes ref names' '
250
- test_completion_long "git checkout m" <<-\EOF
247
+ test_completion "git checkout m" <<-\EOF
248
master Z
249
mybranch Z
250
mytag Z
@@ -255,7 +252,7 @@ test_expect_success 'checkout completes ref names' '
252
'
253
254
test_expect_success 'show completes all refs' '
258
- test_completion_long "git show m" <<-\EOF
255
+ test_completion "git show m" <<-\EOF
256
master Z
257
mybranch Z
258
mytag Z
@@ -263,7 +260,7 @@ test_expect_success 'show completes all refs' '
260
'
261
262
test_expect_success '<ref>: completes paths' '
266
- test_completion_long "git show mytag:f" <<-\EOF
263
+ test_completion "git show mytag:f" <<-\EOF
264
file1 Z
265
file2 Z
266
EOF
@@ -273,7 +270,7 @@ test_expect_success 'complete tree filename with spaces' '
270
echo content >"name with spaces" &&
271
git add . &&
272
git commit -m spaces &&
276
- test_completion_long "git show HEAD:nam" <<-\EOF
273
+ test_completion "git show HEAD:nam" <<-\EOF
274
name with spaces Z
275
EOF
276
'
@@ -282,7 +279,7 @@ test_expect_failure 'complete tree filename with metacharacters' '
279
echo content >"name with \${meta}" &&
280
git add . &&
281
git commit -m meta &&
285
- test_completion_long "git show HEAD:nam" <<-\EOF
282
+ test_completion "git show HEAD:nam" <<-\EOF
283
name with ${meta} Z
284
name with spaces Z
285
EOF