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

Re: [PATCH 11/14] test: completion: tests for __gitcomp regression

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Jul 3, 2019, 17:49 UTC
Message-ID
<20190703174909.GU21574@szeder.dev>
In-Reply-To
<20190621223107.8022-12-felipe.contreras@gmail.com>
On Fri, Jun 21, 2019 at 05:31:04PM -0500, Felipe Contreras wrote:
Show 14 quoted lines
> There's a regression in the completion since the introduction of
> __gitcomp.
> 
> Go to any directory that doesn't contain a git repository, like /tmp.
> Then type the following:
> 
>   git checkout --<tab>
> 
> You will see nothing. That's because
> `git checkout --git-completion-helper` fails when you run it outside a
> git repository.
> 
> You might change to a directory that has a git repository, but it's too
> late, because the empty options have been cached.

This will get outdated rather soonish, as soon as 69702523af (completion: do not cache if --git-completion-helper fails, 2019-06-12) graduates to master.

> It's unclear how many commands are affected, but this patch attempts to
> at least detect some already in the testing framework.

It seems that several changes in this patch modify tests in a way that defeats the purpose of the given test, e.g. the tests 'completion.commands removes multiple commands' or 'sourcing the completion script clears cached merge strategies'

I would rather see tests specifically focusing on the __gitcomp_builtin() helper function, including test cases when it's excersized outside of a repository and when it gets additional parameters to include and exclude some options.

Show 20 quoted lines
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  t/t9902-completion.sh | 37 ++++++++++++++++++++++++++++---------
>  1 file changed, 28 insertions(+), 9 deletions(-)
> 
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 43cf313a1c..7bef41eaf5 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -122,6 +122,15 @@ test_gitcomp_nl ()
>  	test_cmp expected out
>  }
>  
> +offgit ()
> +{
> +	GIT_CEILING_DIRECTORIES="$ROOT" &&
> +	export GIT_CEILING_DIRECTORIES &&
> +	test_when_finished "ROOT='$ROOT'; cd '$TRASH_DIRECTORY'; unset GIT_CEILING_DIRECTORIES" &&
> +	ROOT="$ROOT"/non-repo &&
> +	cd "$ROOT"
I think fiddling with $ROOT is unnecessary here.
Show 124 quoted lines
> +}
> +
>  invalid_variable_name='${foo.bar}'
>  
>  actual="$TRASH_DIRECTORY/actual"
> @@ -358,10 +367,8 @@ test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symli
>  '
>  
>  test_expect_success '__git_find_repo_path - not a git repository' '
> +	offgit &&
>  	(
> -		cd non-repo &&
> -		GIT_CEILING_DIRECTORIES="$ROOT" &&
> -		export GIT_CEILING_DIRECTORIES &&
>  		test_must_fail __git_find_repo_path &&
>  		printf "$__git_repo_path" >"$actual"
>  	) &&
> @@ -1388,6 +1395,7 @@ test_expect_success '__git_pretty_aliases' '
>  '
>  
>  test_expect_success 'basic' '
> +	offgit &&
>  	run_completion "git " &&
>  	# built-in
>  	grep -q "^add \$" out &&
> @@ -1401,6 +1409,7 @@ test_expect_success 'basic' '
>  '
>  
>  test_expect_success 'double dash "git" itself' '
> +	offgit &&
>  	test_completion "git --" <<-\EOF
>  	--paginate Z
>  	--no-pager Z
> @@ -1419,7 +1428,8 @@ test_expect_success 'double dash "git" itself' '
>  	EOF
>  '
>  
> -test_expect_success 'double dash "git checkout"' '
> +test_expect_failure 'double dash "git checkout"' '
> +	offgit &&
>  	test_completion "git checkout --" <<-\EOF
>  	--quiet Z
>  	--detach Z
> @@ -1442,6 +1452,7 @@ test_expect_success 'double dash "git checkout"' '
>  '
>  
>  test_expect_success 'general options' '
> +	offgit &&
>  	test_completion "git --ver" "--version " &&
>  	test_completion "git --hel" "--help " &&
>  	test_completion "git --exe" <<-\EOF &&
> @@ -1460,6 +1471,7 @@ test_expect_success 'general options' '
>  '
>  
>  test_expect_success 'general options plus command' '
> +	offgit &&
>  	test_completion "git --version check" "checkout " &&
>  	test_completion "git --paginate check" "checkout " &&
>  	test_completion "git --git-dir=foo check" "checkout " &&
> @@ -1480,11 +1492,13 @@ test_expect_success 'general options plus command' '
>  '
>  
>  test_expect_success 'git --help completion' '
> +	offgit &&
>  	test_completion "git --help ad" "add " &&
>  	test_completion "git --help core" "core-tutorial "
>  '
>  
> -test_expect_success 'completion.commands removes multiple commands' '
> +test_expect_failure 'completion.commands removes multiple commands' '
> +	offgit &&
>  	test_config completion.commands "-cherry -mergetool" &&
>  	git --list-cmds=list-mainporcelain,list-complete,config >out &&
>  	! grep -E "^(cherry|mergetool)$" out
> @@ -1547,9 +1561,10 @@ test_expect_success 'complete tree filename with metacharacters' '
>  	EOF
>  '
>  
> -test_expect_success PERL 'send-email' '
> -	test_completion "git send-email --cov" "--cover-letter " &&
> -	test_completion "git send-email ma" "master "
> +test_expect_failure PERL 'send-email' '
> +	test_completion "git send-email ma" "master " &&
> +	offgit &&
> +	test_completion "git send-email --cov" "--cover-letter "
>  '
>  
>  test_expect_success 'complete files' '
> @@ -1649,6 +1664,7 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
>  '
>  
>  test_expect_success 'completion without explicit _git_xxx function' '
> +	offgit &&
>  	test_completion "git version --" <<-\EOF
>  	--build-options Z
>  	--no-build-options Z
> @@ -1699,13 +1715,15 @@ do
>  done
>  
>  test_expect_success 'sourcing the completion script clears cached commands' '
> +	offgit &&
>  	__git_compute_all_commands &&
>  	verbose test -n "$__git_all_commands" &&
>  	. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
>  	verbose test -z "$__git_all_commands"
>  '
>  
> -test_expect_success 'sourcing the completion script clears cached merge strategies' '
> +test_expect_failure 'sourcing the completion script clears cached merge strategies' '
> +	offgit &&
>  	GIT_TEST_GETTEXT_POISON= &&
>  	__git_compute_merge_strategies &&
>  	verbose test -n "$__git_merge_strategies" &&
> @@ -1714,6 +1732,7 @@ test_expect_success 'sourcing the completion script clears cached merge strategi
>  '
>  
>  test_expect_success 'sourcing the completion script clears cached --options' '
> +	offgit &&
>  	__gitcomp_builtin checkout &&
>  	verbose test -n "$__gitcomp_builtin_checkout" &&
>  	__gitcomp_builtin notes_edit &&
> -- 
> 2.22.0
> 
Previous: Junio C HamanoNext: Felipe Contreras
Message 14 of 58 in “completion: a bunch of updates”
  1. 00/14 completion: a bunch of updatesFelipe Contreras, Jun 21, 2019
  2. 01/14 completion: zsh: fix __gitcomp_direct()Felipe Contreras, Jun 21, 2019
  3. Felipe ContrerasJun 22, 2019
  4. 02/14 completion: zsh: fix for directories with spacesFelipe Contreras, Jun 21, 2019
  5. 03/14 completion: remove zsh hackFelipe Contreras, Jun 21, 2019
  6. 04/14 completion: zsh: improve main function selectionFelipe Contreras, Jun 21, 2019
  7. 05/14 completion: prompt: fix color for ZshFelipe Contreras, Jun 21, 2019
  8. 08/14 completion: bash: remove old compat wrappersFelipe Contreras, Jun 21, 2019
  9. 07/14 completion: zsh: update installation instructionsFelipe Contreras, Jun 21, 2019
  10. 06/14 completion: bash: cleanup cygwin checkFelipe Contreras, Jun 21, 2019
  11. 09/14 completion: bash: remove zsh wrapperFelipe Contreras, Jun 21, 2019
  12. 11/14 test: completion: tests for __gitcomp regressionFelipe Contreras, Jun 21, 2019
  13. Junio C HamanoJul 3, 2019
  14. SZEDER GáborJul 3, 2019
  15. 10/14 completion: zsh: trivial cleanupsFelipe Contreras, Jun 21, 2019
  16. 12/14 test: completion: use global configFelipe Contreras, Jun 21, 2019
  17. Junio C HamanoJul 3, 2019
  18. 13/14 completion: add default optionsFelipe Contreras, Jun 21, 2019
  19. Duy NguyenJun 22, 2019
  20. Felipe ContrerasJun 22, 2019
  21. Junio C HamanoJun 24, 2019
  22. Felipe ContrerasJun 25, 2019
  23. Duy NguyenJun 25, 2019
  24. 14/14 completion: add default merge strategiesFelipe Contreras, Jun 21, 2019
  25. Junio C HamanoJun 24, 2019
  26. Felipe ContrerasJun 25, 2019
  27. Junio C HamanoJun 25, 2019
  28. SZEDER GáborJul 3, 2019
  29. Junio C HamanoJul 3, 2019
  30. SZEDER GáborJul 3, 2019
  31. Felipe ContrerasOct 25, 2020
  32. Felipe ContrerasOct 25, 2020
  33. Junio C HamanoOct 27, 2020
  34. Felipe ContrerasOct 27, 2020
  35. Junio C HamanoOct 27, 2020
  36. Felipe ContrerasOct 28, 2020
  37. Stefan HallerOct 28, 2020
  38. Felipe ContrerasOct 28, 2020
  39. Stefan HallerOct 28, 2020
  40. Junio C HamanoOct 29, 2020
  41. Junio C HamanoOct 29, 2020
  42. Felipe ContrerasNov 2, 2020
  43. Junio C HamanoNov 3, 2020
  44. Felipe ContrerasNov 4, 2020
  45. Junio C HamanoNov 4, 2020
  46. Felipe ContrerasNov 5, 2020
  47. Junio C HamanoNov 5, 2020
  48. Stefan HallerOct 30, 2020
  49. Junio C HamanoOct 30, 2020
  50. Felipe ContrerasNov 2, 2020
  51. Aaron SchrabNov 2, 2020
  52. Junio C HamanoNov 3, 2020
  53. Felipe ContrerasNov 3, 2020
  54. Felipe ContrerasNov 3, 2020
  55. Stefan HallerNov 3, 2020
  56. Junio C HamanoNov 3, 2020
  57. Stefan HallerNov 3, 2020
  58. Felipe ContrerasNov 2, 2020

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.