From 49ba92b4eaca44ee4d7444b2256d60c2f32268ee Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 26 Sep 2012 17:47:51 -0400 Subject: t9902: add a few basic completion tests We were not testing ref or tree completion at all. Let's give them even basic sanity checks to avoid regressions. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t9902-completion.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 't') diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 92d7eb47c2..2fc833ad8b 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -61,6 +61,15 @@ test_completion () test_cmp expected out } +# Like test_completion, but reads expectation from stdin, +# which is convenient when it is multiline. We also process "_" into +# spaces to make test vectors more readable. +test_completion_long () +{ + tr _ " " >expected && + test_completion "$1" +} + newline=$'\n' test_expect_success '__gitcomp - trailing space - options' ' @@ -228,4 +237,36 @@ test_expect_success 'general options plus command' ' test_completion "git --no-replace-objects check" "checkout " ' +test_expect_success 'setup for ref completion' ' + echo content >file1 && + echo more >file2 && + git add . && + git commit -m one && + git branch mybranch && + git tag mytag +' + +test_expect_success 'checkout completes ref names' ' + test_completion_long "git checkout m" <<-\EOF + master_ + mybranch_ + mytag_ + EOF +' + +test_expect_success 'show completes all refs' ' + test_completion_long "git show m" <<-\EOF + master_ + mybranch_ + mytag_ + EOF +' + +test_expect_success ': completes paths' ' + test_completion_long "git show mytag:f" <<-\EOF + file1_ + file2_ + EOF +' + test_done -- cgit v1.2.3 From bafed0dfb405b27e8b2b9680beece1dfaf5fdab2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 26 Sep 2012 17:51:06 -0400 Subject: t9902: add completion tests for "odd" filenames We correctly handle completion items with spaces just fine, since we pass the lists around with newline delimiters. However, we do not handle filenames with shell metacharacters, as "compgen -W" performs expansion on the list we give it. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t9902-completion.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 't') diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 2fc833ad8b..cbd0fb66f9 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -269,4 +269,23 @@ test_expect_success ': completes paths' ' EOF ' +test_expect_success 'complete tree filename with spaces' ' + echo content >"name with spaces" && + git add . && + git commit -m spaces && + test_completion_long "git show HEAD:nam" <<-\EOF + name with spaces_ + EOF +' + +test_expect_failure 'complete tree filename with metacharacters' ' + echo content >"name with \${meta}" && + git add . && + git commit -m meta && + test_completion_long "git show HEAD:nam" <<-\EOF + name with ${meta}_ + name with spaces_ + EOF +' + test_done -- cgit v1.2.3