Skip to content

Commit abc05cb

Browse files
committed
Merge branch 'jk/completion-tests'
* jk/completion-tests: t9902: add completion tests for "odd" filenames t9902: add a few basic completion tests
2 parents 70dac5f + bafed0d commit abc05cb

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

t/t9902-completion.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ test_completion ()
6161
test_cmp expected out
6262
}
6363

64+
# Like test_completion, but reads expectation from stdin,
65+
# which is convenient when it is multiline. We also process "_" into
66+
# spaces to make test vectors more readable.
67+
test_completion_long ()
68+
{
69+
tr _ " " >expected &&
70+
test_completion "$1"
71+
}
72+
6473
newline=$'\n'
6574

6675
test_expect_success '__gitcomp - trailing space - options' '
@@ -228,4 +237,55 @@ test_expect_success 'general options plus command' '
228237
test_completion "git --no-replace-objects check" "checkout "
229238
'
230239

240+
test_expect_success 'setup for ref completion' '
241+
echo content >file1 &&
242+
echo more >file2 &&
243+
git add . &&
244+
git commit -m one &&
245+
git branch mybranch &&
246+
git tag mytag
247+
'
248+
249+
test_expect_success 'checkout completes ref names' '
250+
test_completion_long "git checkout m" <<-\EOF
251+
master_
252+
mybranch_
253+
mytag_
254+
EOF
255+
'
256+
257+
test_expect_success 'show completes all refs' '
258+
test_completion_long "git show m" <<-\EOF
259+
master_
260+
mybranch_
261+
mytag_
262+
EOF
263+
'
264+
265+
test_expect_success '<ref>: completes paths' '
266+
test_completion_long "git show mytag:f" <<-\EOF
267+
file1_
268+
file2_
269+
EOF
270+
'
271+
272+
test_expect_success 'complete tree filename with spaces' '
273+
echo content >"name with spaces" &&
274+
git add . &&
275+
git commit -m spaces &&
276+
test_completion_long "git show HEAD:nam" <<-\EOF
277+
name with spaces_
278+
EOF
279+
'
280+
281+
test_expect_failure 'complete tree filename with metacharacters' '
282+
echo content >"name with \${meta}" &&
283+
git add . &&
284+
git commit -m meta &&
285+
test_completion_long "git show HEAD:nam" <<-\EOF
286+
name with ${meta}_
287+
name with spaces_
288+
EOF
289+
'
290+
231291
test_done

0 commit comments

Comments
 (0)