From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:14
These started from a discussion with SZEDER, but then I realized there were
many improvements possible.
Changes since v1:
* A lot more cleanups
Felipe Contreras (6):
completion: add comment for test_completion()
completion: standardize final space marker in tests
completion: simplify tests using test_completion_long()
completion: consolidate test_completion*() tests
completion: refactor __gitcomp related tests
completion: simplify __gitcomp() test helper
t/t9902-completion.sh | 133 +++++++++++++++++++-------------------------------
1 file changed, 51 insertions(+), 82 deletions(-)
--
1.8.0
From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:14
The rest of the code uses ' Z$'. Lets use that for
test_completion_long() as well.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
@@ -66,11 +66,10 @@ test_completion ()}# 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.+# which is convenient when it is multiline. test_completion_long(){-tr_" ">expected&&+sed-e's/Z$//'>expected&&test_completion"$1"}
@@ -252,24 +251,24 @@ test_expect_success 'setup for ref completion' ' test_expect_success'checkout completes ref names''test_completion_long"git checkout m"<<-\EOF-master_-mybranch_-mytag_+masterZ+mybranchZ+mytagZEOF' test_expect_success'show completes all refs''test_completion_long"git show m"<<-\EOF-master_-mybranch_-mytag_+masterZ+mybranchZ+mytagZEOF' test_expect_success'<ref>: completes paths''test_completion_long"git show mytag:f"<<-\EOF-file1_-file2_+file1Z+file2ZEOF'
@@ -278,7 +277,7 @@ test_expect_success 'complete tree filename with spaces' 'gitadd.&&gitcommit-mspaces&&test_completion_long"git show HEAD:nam"<<-\EOF-namewithspaces_+namewithspacesZEOF'
@@ -287,8 +286,8 @@ test_expect_failure 'complete tree filename with metacharacters' 'gitadd.&&gitcommit-mmeta&&test_completion_long"git show HEAD:nam"<<-\EOF-namewith${meta}_-namewithspaces_+namewith${meta}Z+namewithspacesZEOF'
From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:14
So that it's easier to understand what it does.
Also, make sure we pass only the first argument for completion.
Shouldn't cause any functional changes because run_completion only
checks $1.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:14
No need to duplicate that functionality.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:14
No need to have two versions; if a second argument is specified, use
that, otherwise use stdin.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 30 +++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)
@@ -60,19 +60,15 @@ run_completion ()# 2: expected completion test_completion(){-test$#-gt1&&echo"$2">expected+if[$#-gt1];then+echo"$2">expected+else+sed-e's/Z$//'>expected+fi&&run_completion"$1"&&test_cmpexpectedout}-# Like test_completion, but reads expectation from stdin,-# which is convenient when it is multiline.-test_completion_long()-{-sed-e's/Z$//'>expected&&-test_completion"$1"-}-newline=$'\n' test_expect_success'__gitcomp - trailing space - options''
@@ -255,7 +251,7 @@ test_expect_success 'checkout completes ref names' '' test_expect_success'show completes all refs''-test_completion_long"git show m"<<-\EOF+test_completion"git show m"<<-\EOFmasterZmybranchZmytagZ
@@ -263,7 +259,7 @@ test_expect_success 'show completes all refs' '' test_expect_success'<ref>: completes paths''-test_completion_long"git show mytag:f"<<-\EOF+test_completion"git show mytag:f"<<-\EOFfile1Zfile2ZEOF
@@ -273,7 +269,7 @@ test_expect_success 'complete tree filename with spaces' 'echocontent>"name with spaces"&&gitadd.&&gitcommit-mspaces&&-test_completion_long"git show HEAD:nam"<<-\EOF+test_completion"git show HEAD:nam"<<-\EOFnamewithspacesZEOF'
@@ -282,7 +278,7 @@ test_expect_failure 'complete tree filename with metacharacters' 'echocontent>"name with \${meta}"&&gitadd.&&gitcommit-mmeta&&-test_completion_long"git show HEAD:nam"<<-\EOF+test_completion"git show HEAD:nam"<<-\EOFnamewith${meta}ZnamewithspacesZEOF
From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:14
By using print_comp as suggested by SZEDER Gábor.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
@@ -69,23 +69,18 @@ test_completion ()test_cmpexpectedout}-newline=$'\n'-# Test __gitcomp.# Arguments are:# 1: typed text so far (cur)# *: arguments to pass to __gitcomp test_gitcomp(){+local-aCOMPREPLY&&sed-e's/Z$//'>expected&&-(-local-aCOMPREPLY&&-cur="$1"&&-shift&&-__gitcomp"$@"&&-IFS="$newline"&&-echo"${COMPREPLY[*]}">out-)&&+cur="$1"&&+shift&&+__gitcomp"$@"&&+print_comp&&test_cmpexpectedout}
From: SZEDER Gábor <hidden> Date: 2016-06-15 22:55:18
On Sun, Nov 11, 2012 at 03:35:53PM +0100, Felipe Contreras wrote:
quoted hunk
So that it's easier to understand what it does.
Also, make sure we pass only the first argument for completion.
Shouldn't cause any functional changes because run_completion only
checks $1.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
@@ -54,10 +54,14 @@ run_completion ()__git_wrap__git_main&&print_comp}+# Test high-level completion+# Arguments are:+# 1: typed text so far (cur)
Bash manuals calls this the current command line or words in the
current command line. I'm not sure what you mean with '(cur)' here.
The variable $cur in the completion script (or in bash-completion in
general) is something completely different.
@@ -71,87 +71,65 @@ test_completion ()newline=$'\n'-test_expect_success'__gitcomp - trailing space - options''-sed-e"s/Z$//">expected<<-\EOF&&---reuse-message=Z---reedit-message=Z---reset-authorZ-EOF+# Test __gitcomp.+# Arguments are:+# 1: typed text so far (cur)
The first argument is not the typed text so far, but the word
currently containing the cursor position.
+# *: arguments to pass to __gitcomp
+test_gitcomp ()
+{
+ sed -e 's/Z$//' > expected &&
(
local -a COMPREPLY &&
- cur="--re" &&
- __gitcomp "--dry-run --reuse-message= --reedit-message=
- --reset-author" &&
+ cur="$1" &&
+ shift &&
+ __gitcomp "$@" &&
IFS="$newline" &&
echo "${COMPREPLY[*]}" > out
) &&
test_cmp expected out
+}
+
+test_expect_success '__gitcomp - trailing space - options' '
+ test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
+ --reset-author" <<-EOF
+ --reuse-message=Z
+ --reedit-message=Z
+ --reset-author Z
+ EOF
'
test_expect_success '__gitcomp - trailing space - config keys' '
- sed -e "s/Z$//" >expected <<-\EOF &&
+ test_gitcomp "br" "branch. branch.autosetupmerge
+ branch.autosetuprebase browser." <<-\EOF
branch.Z
branch.autosetupmerge Z
branch.autosetuprebase Z
browser.Z
EOF
- (
- local -a COMPREPLY &&
- cur="br" &&
- __gitcomp "branch. branch.autosetupmerge
- branch.autosetuprebase browser." &&
- IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
- ) &&
- test_cmp expected out
'
test_expect_success '__gitcomp - option parameter' '
- sed -e "s/Z$//" >expected <<-\EOF &&
+ test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
+ "" "re" <<-\EOF
recursive Z
resolve Z
EOF
- (
- local -a COMPREPLY &&
- cur="--strategy=re" &&
- __gitcomp "octopus ours recursive resolve subtree
- " "" "re" &&
- IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
- ) &&
- test_cmp expected out
'
test_expect_success '__gitcomp - prefix' '
- sed -e "s/Z$//" >expected <<-\EOF &&
+ test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
+ "branch.maint." "me" <<-\EOF
branch.maint.merge Z
branch.maint.mergeoptions Z
EOF
- (
- local -a COMPREPLY &&
- cur="branch.me" &&
- __gitcomp "remote merge mergeoptions rebase
- " "branch.maint." "me" &&
- IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
- ) &&
- test_cmp expected out
'
test_expect_success '__gitcomp - suffix' '
- sed -e "s/Z$//" >expected <<-\EOF &&
+ test_gitcomp "branch.me" "master maint next pu" "branch." \
+ "ma" "." <<-\EOF
branch.master.Z
branch.maint.Z
EOF
- (
- local -a COMPREPLY &&
- cur="branch.me" &&
- __gitcomp "master maint next pu
- " "branch." "ma" "." &&
- IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
- ) &&
- test_cmp expected out
'
test_expect_success 'basic' '
--
1.8.0
From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:18
On Fri, Nov 16, 2012 at 9:54 PM, SZEDER Gábor [off-list ref] wrote:
On Sun, Nov 11, 2012 at 03:35:53PM +0100, Felipe Contreras wrote:
quoted
So that it's easier to understand what it does.
Also, make sure we pass only the first argument for completion.
Shouldn't cause any functional changes because run_completion only
checks $1.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:18
On Fri, Nov 16, 2012 at 10:06 PM, Felipe Contreras
[off-list ref] wrote:
On Fri, Nov 16, 2012 at 9:54 PM, SZEDER Gábor [off-list ref] wrote:
quoted
On Sun, Nov 11, 2012 at 03:35:53PM +0100, Felipe Contreras wrote:
quoted
So that it's easier to understand what it does.
Also, make sure we pass only the first argument for completion.
Shouldn't cause any functional changes because run_completion only
checks $1.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
From: Junio C Hamano <hidden> Date: 2016-06-15 22:55:18
Felipe Contreras [off-list ref] writes:
quoted hunk
No need to have two versions; if a second argument is specified, use
that, otherwise use stdin.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 30 +++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)
As "$2" could begin with dash, end with \c, etc. that possibly can
be misinterpred by echo, I'd rewrite this as
printf '%s\n' "$2" >expected
Otherwise looked fine; thanks.
From: Felipe Contreras <hidden> Date: 2016-06-15 22:55:19
On Sat, Nov 17, 2012 at 12:41 AM, Junio C Hamano [off-list ref] wrote:
Felipe Contreras [off-list ref] writes:
quoted
No need to have two versions; if a second argument is specified, use
that, otherwise use stdin.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 30 +++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)
As "$2" could begin with dash, end with \c, etc. that possibly can
be misinterpred by echo, I'd rewrite this as
printf '%s\n' "$2" >expected
Otherwise looked fine; thanks.
But that was the case before. I would do that in a separate patch.
Cheers.
--
Felipe Contreras