Skip to content

Commit 2fbaf81

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a1be444 commit 2fbaf81

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

t/t9902-completion.sh

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,16 @@ run_completion ()
6060
# 2: expected completion
6161
test_completion ()
6262
{
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 &&
6469
run_completion "$1" &&
6570
test_cmp expected out
6671
}
6772

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-
7673
newline=$'\n'
7774

7875
test_expect_success '__gitcomp - trailing space - options' '
@@ -172,7 +169,7 @@ test_expect_success 'basic' '
172169
'
173170

174171
test_expect_success 'double dash "git" itself' '
175-
test_completion_long "git --" <<-\EOF
172+
test_completion "git --" <<-\EOF
176173
--paginate Z
177174
--no-pager Z
178175
--git-dir=
@@ -190,7 +187,7 @@ test_expect_success 'double dash "git" itself' '
190187
'
191188

192189
test_expect_success 'double dash "git checkout"' '
193-
test_completion_long "git checkout --" <<-\EOF
190+
test_completion "git checkout --" <<-\EOF
194191
--quiet Z
195192
--ours Z
196193
--theirs Z
@@ -206,7 +203,7 @@ test_expect_success 'double dash "git checkout"' '
206203
test_expect_success 'general options' '
207204
test_completion "git --ver" "--version " &&
208205
test_completion "git --hel" "--help " &&
209-
test_completion_long "git --exe" <<-\EOF &&
206+
test_completion "git --exe" <<-\EOF &&
210207
--exec-path Z
211208
--exec-path=
212209
EOF
@@ -247,23 +244,23 @@ test_expect_success 'setup for ref completion' '
247244
'
248245

249246
test_expect_success 'checkout completes ref names' '
250-
test_completion_long "git checkout m" <<-\EOF
247+
test_completion "git checkout m" <<-\EOF
251248
master Z
252249
mybranch Z
253250
mytag Z
254251
EOF
255252
'
256253

257254
test_expect_success 'show completes all refs' '
258-
test_completion_long "git show m" <<-\EOF
255+
test_completion "git show m" <<-\EOF
259256
master Z
260257
mybranch Z
261258
mytag Z
262259
EOF
263260
'
264261

265262
test_expect_success '<ref>: completes paths' '
266-
test_completion_long "git show mytag:f" <<-\EOF
263+
test_completion "git show mytag:f" <<-\EOF
267264
file1 Z
268265
file2 Z
269266
EOF
@@ -273,7 +270,7 @@ test_expect_success 'complete tree filename with spaces' '
273270
echo content >"name with spaces" &&
274271
git add . &&
275272
git commit -m spaces &&
276-
test_completion_long "git show HEAD:nam" <<-\EOF
273+
test_completion "git show HEAD:nam" <<-\EOF
277274
name with spaces Z
278275
EOF
279276
'
@@ -282,7 +279,7 @@ test_expect_failure 'complete tree filename with metacharacters' '
282279
echo content >"name with \${meta}" &&
283280
git add . &&
284281
git commit -m meta &&
285-
test_completion_long "git show HEAD:nam" <<-\EOF
282+
test_completion "git show HEAD:nam" <<-\EOF
286283
name with ${meta} Z
287284
name with spaces Z
288285
EOF

0 commit comments

Comments
 (0)