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

2012-11-18 Thread Felipe Contreras
On Sat, Nov 17, 2012 at 12:05 PM, SZEDER Gábor sze...@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 sze...@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
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2012-11-17 Thread Jonathan Nieder
SZEDER Gábor wrote:

 --- a/t/t9902-completion.sh
 +++ b/t/t9902-completion.sh
 @@ -155,6 +155,90 @@ test_expect_success '__gitcomp - suffix' '
   test_cmp expected out
  '
  
 +test_expect_success '__gitcomp_nl - trailing space' '
 + sed -e s/Z$// expected -\EOF 

'$' is usually a shell metacharacter, so it would be more comfortable
to read a version that escapes it:

sed -e s/Z\$// expected -\EOF

Since '$/' is not a valid parameter expansion, if I understand
correctly then POSIX leaves the meaning of the quoted string s/Z$//
undefined (XCU §2.2.3).  Luckily every shell I've tried, including
bash, keeps the $ unmolested.

Other parts of the file already use the same style, so I wouldn't
suggest changing it in this patch.

Thanks for some nice tests.

Reviewed-by: Jonathan Nieder jrnie...@gmail.com
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html