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

Re: [PATCH 3/7] completion: add tests for the __gitcomp_nl() completion helper function

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Nov 18, 2012, 08:53 UTC
Message-ID
<CAMP44s1CFPt5ZmDuOEbLnsz5ShSSCO3O7Ws0CkMhjrpnkOMdJw@mail.gmail.com>
In-Reply-To
<1353150353-29874-4-git-send-email-szeder@ira.uka.de>
On Sat, Nov 17, 2012 at 12:05 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:
Show 7 quoted lines
> Test __gitcomp_nl()'s basic functionality, i.e. that trailing space,
> prefix, and suffix are added correctly.
>
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
>  t/t9902-completion.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 84 insertions(+)
Too much code that can be simplified:
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -85,6 +85,22 @@ test_gitcomp ()
 	test_cmp expected out
 }

+# Test __gitcomp_nl
+# Arguments are:
+# 1: typed text so far (cur)
+# -: the rest are passed to __gitcomp_nl
+test_gitcomp_nl ()
+{
+	local -a COMPREPLY &&
+	sed -e 's/Z$//' > expected &&
+	cur="$1" &&
+	shift &&
+	__gitcomp_nl "$@" &&
+	print_comp &&
+	cp expected out /tmp
+	test_cmp expected out
+}
+
 invalid_variable_name="${foo.bar}"

 test_expect_success '__gitcomp - trailing space - options' '
@@ -134,88 +150,39 @@ test_expect_success '__gitcomp - doesnt fail
because of invalid variable name' '
 	__gitcomp "$invalid_variable_name"
 '

+read -r -d "" refs <<-\EOF
+maint
+master
+next
+pu
+EOF
+
 test_expect_success '__gitcomp_nl - trailing space' '
-	sed -e "s/Z$//" >expected <<-\EOF &&
+	test_gitcomp_nl "m" "$refs" <<-EOF
 	maint Z
 	master Z
 	EOF
-	(
-		declare -a COMPREPLY &&
-		refs="$(cat <<-\EOF
-			maint
-			master
-			next
-			pu
-			EOF
-		)" &&
-		cur="m" &&
-		__gitcomp_nl "$refs" &&
-		print_comp
-	) &&
-	test_cmp expected out
 '

 test_expect_success '__gitcomp_nl - prefix' '
-	sed -e "s/Z$//" >expected <<-\EOF &&
+	test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
 	--fixup=maint Z
 	--fixup=master Z
 	EOF
-	(
-		declare -a COMPREPLY &&
-		refs="$(cat <<-\EOF
-			maint
-			master
-			next
-			pu
-			EOF
-		)" &&
-		cur="--fixup=m" &&
-		__gitcomp_nl "$refs" "--fixup=" "m" &&
-		print_comp
-	) &&
-	test_cmp expected out
 '

 test_expect_success '__gitcomp_nl - suffix' '
-	sed -e "s/Z$//" >expected <<-\EOF &&
+	test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
 	branch.maint.Z
 	branch.master.Z
 	EOF
-	(
-		declare -a COMPREPLY &&
-		refs="$(cat <<-\EOF
-			maint
-			master
-			next
-			pu
-			EOF
-		)" &&
-		cur="branch.ma" &&
-		__gitcomp_nl "$refs" "branch." "ma" "." &&
-		print_comp
-	) &&
-	test_cmp expected out
 '

 test_expect_success '__gitcomp_nl - no suffix' '
-	sed -e "s/Z$//" >expected <<-\EOF &&
+	test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
 	maintZ
 	masterZ
 	EOF
-	(
-		declare -a COMPREPLY &&
-		refs="$(cat <<-\EOF
-			maint
-			master
-			next
-			pu
-			EOF
-		)" &&
-		cur="ma" &&
-		__gitcomp_nl "$refs" "" "ma" "" &&
-		print_comp
-	) &&
-	test_cmp expected out
 '

 test_expect_success '__gitcomp_nl - doesnt fail because of invalid
variable name' '

Cheers.
-- 
Felipe Contreras
Previous: Jonathan NiederNext: SZEDER Gábor
Message 11 of 26 in “completion: fix expansion issues with compgen”
  1. 0/7 completion: fix expansion issues with compgenSZEDER Gábor, Nov 17, 2012
  2. 1/7 completion: make the 'basic' test more tester-friendlySZEDER Gábor, Nov 17, 2012
  3. Jonathan NiederNov 17, 2012
  4. Felipe ContrerasNov 18, 2012
  5. Felipe ContrerasNov 18, 2012
  6. 2/7 completion: fix args of run_completion() test helperSZEDER Gábor, Nov 17, 2012
  7. Jonathan NiederNov 17, 2012
  8. Felipe ContrerasNov 18, 2012
  9. 3/7 completion: add tests for the __gitcomp_nl() completion helper functionSZEDER Gábor, Nov 17, 2012
  10. Jonathan NiederNov 17, 2012
  11. Felipe ContrerasNov 18, 2012
  12. 4/7 completion: add tests for invalid variable name among completion wordsSZEDER Gábor, Nov 17, 2012
  13. Jonathan NiederNov 17, 2012
  14. Felipe ContrerasNov 18, 2012
  15. Felipe ContrerasNov 18, 2012
  16. 5/7 completion: fix expansion issues in __gitcomp_nl()SZEDER Gábor, Nov 17, 2012
  17. Felipe ContrerasNov 17, 2012
  18. SZEDER GáborNov 17, 2012
  19. Felipe ContrerasNov 17, 2012
  20. Felipe ContrerasNov 17, 2012
  21. Felipe ContrerasNov 18, 2012
  22. Felipe ContrerasNov 18, 2012
  23. 6/7 completion: fix expansion issue in __gitcomp()SZEDER Gábor, Nov 17, 2012
  24. Felipe ContrerasNov 17, 2012
  25. SZEDER GáborNov 17, 2012
  26. 7/7 completion: remove the now unused __gitcomp_1() internal helper functionSZEDER Gábor, Nov 17, 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.