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

[PATCH v7 15/49] test: completion: add run_func() helper

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 1, 2023, 08:45 UTC
Message-ID
<20230401084626.304356-16-felipe.contreras@gmail.com>
In-Reply-To
<20230401084626.304356-1-felipe.contreras@gmail.com>
Pretty straightforward: runs functions.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 t/t9902-completion.sh | 58 ++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 34 deletions(-)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 9d973f21ce..a2f2f9dc09 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -75,6 +75,12 @@ run_completion ()
 	__git_wrap__git_main && print_comp
 }
 
+run_func ()
+{
+	local -a COMPREPLY &&
+	"$@" && print_comp
+}
+
 # Test high-level completion
 # Arguments are:
 # 1: typed text so far (cur)
@@ -452,8 +458,7 @@ test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '
 	EOF
 	(
 		cur=should_be_ignored &&
-		__gitcomp_direct "$(cat expected)" &&
-		print_comp
+		run_func __gitcomp_direct "$(cat expected)"
 	) &&
 	test_cmp expected out
 '
@@ -547,7 +552,7 @@ test_expect_success '__gitcomp - equal skip' '
 '
 
 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
-	__gitcomp "$invalid_variable_name"
+	run_func __gitcomp "$invalid_variable_name"
 '
 
 read -r -d "" refs <<-\EOF
@@ -586,7 +591,7 @@ test_expect_success '__gitcomp_nl - no suffix' '
 '
 
 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '
-	__gitcomp_nl "$invalid_variable_name"
+	run_func __gitcomp_nl "$invalid_variable_name"
 '
 
 test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
@@ -1087,8 +1092,7 @@ test_expect_success '__git_complete_refs - simple' '
 	EOF
 	(
 		cur= &&
-		__git_complete_refs &&
-		print_comp
+		run_func __git_complete_refs
 	) &&
 	test_cmp expected out
 '
@@ -1100,8 +1104,7 @@ test_expect_success '__git_complete_refs - matching' '
 	EOF
 	(
 		cur=mat &&
-		__git_complete_refs &&
-		print_comp
+		run_func __git_complete_refs
 	) &&
 	test_cmp expected out
 '
@@ -1114,8 +1117,7 @@ test_expect_success '__git_complete_refs - remote' '
 	EOF
 	(
 		cur= &&
-		__git_complete_refs --remote=other &&
-		print_comp
+		run_func __git_complete_refs --remote=other
 	) &&
 	test_cmp expected out
 '
@@ -1133,8 +1135,7 @@ test_expect_success '__git_complete_refs - track' '
 	EOF
 	(
 		cur= &&
-		__git_complete_refs --track &&
-		print_comp
+		run_func __git_complete_refs --track
 	) &&
 	test_cmp expected out
 '
@@ -1146,8 +1147,7 @@ test_expect_success '__git_complete_refs - current word' '
 	EOF
 	(
 		cur="--option=mat" &&
-		__git_complete_refs --cur="${cur#*=}" &&
-		print_comp
+		run_func __git_complete_refs --cur="${cur#*=}"
 	) &&
 	test_cmp expected out
 '
@@ -1159,8 +1159,7 @@ test_expect_success '__git_complete_refs - prefix' '
 	EOF
 	(
 		cur=v1.0..mat &&
-		__git_complete_refs --pfx=v1.0.. --cur=mat &&
-		print_comp
+		run_func __git_complete_refs --pfx=v1.0.. --cur=mat
 	) &&
 	test_cmp expected out
 '
@@ -1176,8 +1175,7 @@ test_expect_success '__git_complete_refs - suffix' '
 	EOF
 	(
 		cur= &&
-		__git_complete_refs --sfx=. &&
-		print_comp
+		run_func __git_complete_refs --sfx=.
 	) &&
 	test_cmp expected out
 '
@@ -1190,8 +1188,7 @@ test_expect_success '__git_complete_fetch_refspecs - simple' '
 	EOF
 	(
 		cur= &&
-		__git_complete_fetch_refspecs other &&
-		print_comp
+		run_func __git_complete_fetch_refspecs other
 	) &&
 	test_cmp expected out
 '
@@ -1202,8 +1199,7 @@ test_expect_success '__git_complete_fetch_refspecs - matching' '
 	EOF
 	(
 		cur=br &&
-		__git_complete_fetch_refspecs other "" br &&
-		print_comp
+		run_func __git_complete_fetch_refspecs other "" br
 	) &&
 	test_cmp expected out
 '
@@ -1216,8 +1212,7 @@ test_expect_success '__git_complete_fetch_refspecs - prefix' '
 	EOF
 	(
 		cur="+" &&
-		__git_complete_fetch_refspecs other "+" ""  &&
-		print_comp
+		run_func __git_complete_fetch_refspecs other "+" ""
 	) &&
 	test_cmp expected out
 '
@@ -1230,8 +1225,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified' '
 	EOF
 	(
 		cur=refs/ &&
-		__git_complete_fetch_refspecs other "" refs/ &&
-		print_comp
+		run_func __git_complete_fetch_refspecs other "" refs/
 	) &&
 	test_cmp expected out
 '
@@ -1244,8 +1238,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
 	EOF
 	(
 		cur=+refs/ &&
-		__git_complete_fetch_refspecs other + refs/ &&
-		print_comp
+		run_func __git_complete_fetch_refspecs other + refs/
 	) &&
 	test_cmp expected out
 '
@@ -1931,8 +1924,7 @@ test_path_completion ()
 		# unusual characters in path names.  By requesting only
 		# untracked files we do not have to bother adding any
 		# paths to the index in those tests.
-		__git_complete_index_file --others &&
-		print_comp
+		run_func __git_complete_index_file --others
 	) &&
 	test_cmp expected out
 }
@@ -2487,8 +2479,7 @@ do
 			words=(git push '$flag' other ma) &&
 			cword=${#words[@]} cur=${words[cword-1]} &&
 			__git_cmd_idx=1 &&
-			__git_complete_remote_or_refspec &&
-			print_comp
+			run_func __git_complete_remote_or_refspec
 		) &&
 		test_cmp expected out
 	'
@@ -2501,8 +2492,7 @@ do
 			words=(git push other '$flag' ma) &&
 			cword=${#words[@]} cur=${words[cword-1]} &&
 			__git_cmd_idx=1 &&
-			__git_complete_remote_or_refspec &&
-			print_comp
+			run_func __git_complete_remote_or_refspec
 		) &&
 		test_cmp expected out
 	'
-- 
2.33.0
Previous: Felipe ContrerasNext: Felipe Contreras
Message 16 of 50 in “completion: git-completion 2.0 patches”
  1. 00/49 completion: git-completion 2.0 patchesFelipe Contreras, Apr 1, 2023
  2. 02/49 completion: bash: trivial cleanupFelipe Contreras, Apr 1, 2023
  3. 01/49 test: completion add test for __git_cmd_idxFelipe Contreras, Apr 1, 2023
  4. 03/49 zsh: remove versionFelipe Contreras, Apr 1, 2023
  5. 04/49 completion: bash: trivial grammar fixFelipe Contreras, Apr 1, 2023
  6. 05/49 completion: zsh: add higher-priority locationFelipe Contreras, Apr 1, 2023
  7. 06/49 zsh: resolve symlink of scriptFelipe Contreras, Apr 1, 2023
  8. 07/49 zsh: simplify realpath dirname idiomFelipe Contreras, Apr 1, 2023
  9. 08/49 test: completion: use global configFelipe Contreras, Apr 1, 2023
  10. 09/49 completion: fix __git_cmd_idx regression for zshFelipe Contreras, Apr 1, 2023
  11. 10/49 completion: fix for suboptions with valueFelipe Contreras, Apr 1, 2023
  12. 11/49 completion: zsh: trivial improvementFelipe Contreras, Apr 1, 2023
  13. 12/49 completion: bash: do not modify COMP_WORDBREAKSFelipe Contreras, Apr 1, 2023
  14. 13/49 test: completion: fix currently typed wordsFelipe Contreras, Apr 1, 2023
  15. 14/49 test: completion: switch __gitcomp_nl prefix testFelipe Contreras, Apr 1, 2023
  16. 15/49 test: completion: add run_func() helperFelipe Contreras, Apr 1, 2023
  17. 16/49 completion: bash: remove non-append functionalityFelipe Contreras, Apr 1, 2023
  18. 17/49 completion: bash: get rid of _append() functionsFelipe Contreras, Apr 1, 2023
  19. 18/49 completion: bash: get rid of any non-append codeFelipe Contreras, Apr 1, 2023
  20. 19/49 completion: zsh: fix options with argumentsFelipe Contreras, Apr 1, 2023
  21. 20/49 completion: zsh: expand --git-dir file argumentFelipe Contreras, Apr 1, 2023
  22. 21/49 completion: zsh: add support for general -C optsFelipe Contreras, Apr 1, 2023
  23. 22/49 completion: zsh: fix for undefined completionsFelipe Contreras, Apr 1, 2023
  24. 23/49 completion: zsh: add support for general -c optsFelipe Contreras, Apr 1, 2023
  25. 24/49 completion: zsh: fix extra space on foo=Felipe Contreras, Apr 1, 2023
  26. 25/49 completion: zsh: add excluded optionsFelipe Contreras, Apr 1, 2023
  27. 26/49 completion: zsh: always set compsetFelipe Contreras, Apr 1, 2023
  28. 27/49 completion: factor out check in __gitcompFelipe Contreras, Apr 1, 2023
  29. 28/49 completion: simplify equal suffix checkFelipe Contreras, Apr 1, 2023
  30. 29/49 completion: refactor __gitcompFelipe Contreras, Apr 1, 2023
  31. 30/49 completion: simplify __gitcompFelipe Contreras, Apr 1, 2023
  32. 31/49 completion: bash: change suffix check in __gitcompFelipe Contreras, Apr 1, 2023
  33. 32/49 completion: improve __gitcomp suffix codeFelipe Contreras, Apr 1, 2023
  34. 33/49 test: completion: add missing testFelipe Contreras, Apr 1, 2023
  35. 34/49 completion: bash: simplify config_variable_nameFelipe Contreras, Apr 1, 2023
  36. 35/49 completion: bash: improve __gitcomp descriptionFelipe Contreras, Apr 1, 2023
  37. 36/49 completion: add __gitcomp_optsFelipe Contreras, Apr 1, 2023
  38. 37/49 completion: bash: cleanup __gitcomp* invocationsFelipe Contreras, Apr 1, 2023
  39. 38/49 completion: bash: shuffle __gitcomp functionsFelipe Contreras, Apr 1, 2023
  40. 39/49 completion: zsh: simplify __gitcomp_directFelipe Contreras, Apr 1, 2023
  41. 40/49 completion: zsh: shuffle __gitcomp* functionsFelipe Contreras, Apr 1, 2023
  42. 41/49 completion: zsh: fix direct quotingFelipe Contreras, Apr 1, 2023
  43. 42/49 completion: zsh: add elements individually in __gitcomp_optsFelipe Contreras, Apr 1, 2023
  44. 43/49 completion: zsh: add __gitcompadd helperFelipe Contreras, Apr 1, 2023
  45. 44/49 completion: zsh: add correct removable suffixFelipe Contreras, Apr 1, 2023
  46. 45/49 completion: bash: simplify _get_comp_words_by_ref()Felipe Contreras, Apr 1, 2023
  47. 46/49 completion: bash: refactor _get_comp_words_by_ref()Felipe Contreras, Apr 1, 2023
  48. 47/49 completion: bash: cleanup _get_comp_words_by_ref()Felipe Contreras, Apr 1, 2023
  49. 48/49 completion: bash: trivial cleanupFelipe Contreras, Apr 1, 2023
  50. 49/49 completion: bash: rename _get_comp_words_by_ref()Felipe Contreras, Apr 1, 2023

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.