git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: "SZEDER Gábor" <szeder@ira.uka.de>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 3/7] completion: add tests for the __gitcomp_nl() completion helper function
Date: Sun, 18 Nov 2012 09:53:57 +0100	[thread overview]
Message-ID: <CAMP44s1CFPt5ZmDuOEbLnsz5ShSSCO3O7Ws0CkMhjrpnkOMdJw@mail.gmail.com> (raw)
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:
> 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

  parent reply	other threads:[~2012-11-18  8:54 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-17 11:05 [PATCH 0/7] completion: fix expansion issues with compgen SZEDER Gábor
2012-11-17 11:05 ` [PATCH 1/7] completion: make the 'basic' test more tester-friendly SZEDER Gábor
2012-11-17 23:00   ` Jonathan Nieder
2012-11-18  9:38     ` Felipe Contreras
2012-11-18  9:39   ` Felipe Contreras
2012-11-17 11:05 ` [PATCH 2/7] completion: fix args of run_completion() test helper SZEDER Gábor
2012-11-17 23:02   ` Jonathan Nieder
2012-11-18  8:48   ` Felipe Contreras
2012-11-17 11:05 ` [PATCH 3/7] completion: add tests for the __gitcomp_nl() completion helper function SZEDER Gábor
2012-11-17 23:31   ` Jonathan Nieder
2012-11-18  8:53   ` Felipe Contreras [this message]
2012-11-17 11:05 ` [PATCH 4/7] completion: add tests for invalid variable name among completion words SZEDER Gábor
2012-11-17 23:40   ` Jonathan Nieder
2012-11-18  8:34     ` Felipe Contreras
2012-11-18  8:34   ` Felipe Contreras
2012-11-17 11:05 ` [PATCH 5/7] completion: fix expansion issues in __gitcomp_nl() SZEDER Gábor
2012-11-17 11:50   ` Felipe Contreras
2012-11-17 14:14     ` SZEDER Gábor
2012-11-17 19:08       ` Felipe Contreras
2012-11-17 19:28         ` Felipe Contreras
2012-11-18  0:55           ` Felipe Contreras
2012-11-18  0:58   ` Felipe Contreras
2012-11-17 11:05 ` [PATCH 6/7] completion: fix expansion issue in __gitcomp() SZEDER Gábor
2012-11-17 11:39   ` Felipe Contreras
2012-11-17 14:09     ` SZEDER Gábor
2012-11-17 11:05 ` [PATCH 7/7] completion: remove the now unused __gitcomp_1() internal helper function SZEDER Gábor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMP44s1CFPt5ZmDuOEbLnsz5ShSSCO3O7Ws0CkMhjrpnkOMdJw@mail.gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=szeder@ira.uka.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).