git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5 2/3] tests: use __gitcompadd to simplify completion tests

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Oct 17, 2012, 17:50 UTC
Message-ID
<20121017175040.GE2156@goldbirke>
In-Reply-To
<1350229971-9343-3-git-send-email-felipe.contreras@gmail.com>
On Sun, Oct 14, 2012 at 05:52:50PM +0200, Felipe Contreras wrote:
Show 20 quoted lines
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  t/t9902-completion.sh | 29 +++++++++--------------------
>  1 file changed, 9 insertions(+), 20 deletions(-)
> 
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 92d7eb4..49c6eb4 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -39,19 +39,18 @@ _get_comp_words_by_ref ()
>  	done
>  }
>  
> -print_comp ()
> +__gitcompadd ()
>  {
> -	local IFS=$'\n'
> -	echo "${COMPREPLY[*]}" > out
> +	compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}" > out
>  }

Please don't. Running compgen is a fundamental part of the completion script, therefore tests must run it as it is in the completion script and not some copy of it.

Show 17 quoted lines
>  run_completion ()
>  {
> -	local -a COMPREPLY _words
> +	local -a _words
>  	local _cword
>  	_words=( $1 )
>  	(( _cword = ${#_words[@]} - 1 ))
> -	__git_wrap__git_main && print_comp
> +	__git_wrap__git_main
>  }
>  
>  test_completion ()
> @@ -70,12 +69,10 @@ test_expect_success '__gitcomp - trailing space - options' '
>  	--reset-author Z
>  	EOF
>  	(
> -		local -a COMPREPLY &&

I'm not sure what I was thinking when I wrote this, but using the local keyword while not within a function but in a subshell doesn't seem to be that clever ;) Maybe just a copy-paste from the local variable declarations of run-completion().

Show 5 quoted lines
>  		cur="--re" &&
>  		__gitcomp "--dry-run --reuse-message= --reedit-message=
>  				--reset-author" &&
> -		IFS="$newline" &&
> -		echo "${COMPREPLY[*]}" > out
And here I should have used print_comp().

All these can be cleaned up without overriding __gitcompadd() and potentialy compromising correctness. Will send a patch in a minute.

> +		IFS="$newline"
This was only necessary for echoing the array.
Show 62 quoted lines
>  	) &&
>  	test_cmp expected out
>  '
> @@ -88,12 +85,10 @@ test_expect_success '__gitcomp - trailing space - config keys' '
>  	browser.Z
>  	EOF
>  	(
> -		local -a COMPREPLY &&
>  		cur="br" &&
>  		__gitcomp "branch. branch.autosetupmerge
>  				branch.autosetuprebase browser." &&
> -		IFS="$newline" &&
> -		echo "${COMPREPLY[*]}" > out
> +		IFS="$newline"
>  	) &&
>  	test_cmp expected out
>  '
> @@ -104,12 +99,10 @@ test_expect_success '__gitcomp - option parameter' '
>  	resolve Z
>  	EOF
>  	(
> -		local -a COMPREPLY &&
>  		cur="--strategy=re" &&
>  		__gitcomp "octopus ours recursive resolve subtree
>  			" "" "re" &&
> -		IFS="$newline" &&
> -		echo "${COMPREPLY[*]}" > out
> +		IFS="$newline"
>  	) &&
>  	test_cmp expected out
>  '
> @@ -120,12 +113,10 @@ test_expect_success '__gitcomp - prefix' '
>  	branch.maint.mergeoptions Z
>  	EOF
>  	(
> -		local -a COMPREPLY &&
>  		cur="branch.me" &&
>  		__gitcomp "remote merge mergeoptions rebase
>  			" "branch.maint." "me" &&
> -		IFS="$newline" &&
> -		echo "${COMPREPLY[*]}" > out
> +		IFS="$newline"
>  	) &&
>  	test_cmp expected out
>  '
> @@ -136,12 +127,10 @@ test_expect_success '__gitcomp - suffix' '
>  	branch.maint.Z
>  	EOF
>  	(
> -		local -a COMPREPLY &&
>  		cur="branch.me" &&
>  		__gitcomp "master maint next pu
>  			" "branch." "ma" "." &&
> -		IFS="$newline" &&
> -		echo "${COMPREPLY[*]}" > out
> +		IFS="$newline"
>  	) &&
>  	test_cmp expected out
>  '
> -- 
> 1.7.12.1
> 
Previous: Felipe ContrerasNext: SZEDER Gábor
Message 8 of 14 in “completion: refactor and zsh wrapper”
  1. 0/3 completion: refactor and zsh wrapperFelipe Contreras, Oct 14, 2012
  2. 1/3 completion: add new __gitcompadd helperFelipe Contreras, Oct 14, 2012
  3. SZEDER GáborOct 17, 2012
  4. Felipe ContrerasOct 22, 2012
  5. SZEDER GáborOct 30, 2012
  6. 2/3 tests: use __gitcompadd to simplify completion testsFelipe Contreras, Oct 14, 2012
  7. Felipe ContrerasOct 16, 2012
  8. SZEDER GáborOct 17, 2012
  9. completion: clean up __gitcomp() testsSZEDER Gábor, Oct 17, 2012
  10. Felipe ContrerasOct 17, 2012
  11. Felipe ContrerasOct 17, 2012
  12. 3/3 completion: add new zsh completionFelipe Contreras, Oct 14, 2012
  13. Felipe ContrerasOct 15, 2012
  14. Matthieu MoyOct 15, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.