[PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD

2012-05-31 Thread Jani Nikula
On Wed, 30 May 2012, Tomi Ollila  wrote:
> On Wed, May 30 2012, Jameson Graef Rollins  
> wrote:
>
>> On Wed, May 30 2012, Mike Kelly  wrote:
>>> FreeBSD's `wc -l` includes some white space in front of the number.
>>> Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures
>>> we do a proper numeric comparision, and in a portable way.
>>
>> Is there a way we can avoid adding another new test function here?  This
>> new function is almost completely identical with the old one, except
>> that it uses "test .. -eq" instead of "[ .. =".  If the problem is just
>> that the arguments occasionally contain superfluous spaces, I would
>> rather see the existing function just strip the spaces.  Of maybe add an
>> option to the test to ask for arithmetic rather than string comparison.
>> That would be preferable to introducing an new function that is
>> confusingly similar to an existing one.
>
> I liked Mike's suggestion as I also thought the options; stripping in
> test_expect_equal cannot be done as there might be whitespace differences
> which mean failure arguments to test_expect_equal cannot be given without
> quotes as variable might be split into multiple args. if test_expect_equal
> were changed to take comparison argument (like '-eq' or '=')  then all
> calls would need to be changes (and function name could be changed to
> something more generic...) None of these sounded as good options...
>
> But, there is at least one option more:
>
> test_expect_equal \
> -"`notmuch search --output=messages ${SEARCH} | wc -l`" \
> +"$((`notmuch search --output=messages ${SEARCH} | wc -l`))" \
> "`notmuch count --output=messages ${SEARCH}`"
>
> this makes arithmetic evaluation -- no operation to be done but
> the spaces around the value are dropped.

But it's non-obvious. How about just adding '| tr -d " "' to the end and
be done with it?

J.


>
>>
>> jamie.
>
> Tomi
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD

2012-05-31 Thread Tomi Ollila
On Wed, May 30 2012, Jameson Graef Rollins  
wrote:

> On Wed, May 30 2012, Mike Kelly  wrote:
>> FreeBSD's `wc -l` includes some white space in front of the number.
>> Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures
>> we do a proper numeric comparision, and in a portable way.
>
> Is there a way we can avoid adding another new test function here?  This
> new function is almost completely identical with the old one, except
> that it uses "test .. -eq" instead of "[ .. =".  If the problem is just
> that the arguments occasionally contain superfluous spaces, I would
> rather see the existing function just strip the spaces.  Of maybe add an
> option to the test to ask for arithmetic rather than string comparison.
> That would be preferable to introducing an new function that is
> confusingly similar to an existing one.

I liked Mike's suggestion as I also thought the options; stripping in
test_expect_equal cannot be done as there might be whitespace differences
which mean failure arguments to test_expect_equal cannot be given without
quotes as variable might be split into multiple args. if test_expect_equal
were changed to take comparison argument (like '-eq' or '=')  then all
calls would need to be changes (and function name could be changed to
something more generic...) None of these sounded as good options...

But, there is at least one option more:

test_expect_equal \
-"`notmuch search --output=messages ${SEARCH} | wc -l`" \
+"$((`notmuch search --output=messages ${SEARCH} | wc -l`))" \
"`notmuch count --output=messages ${SEARCH}`"

this makes arithmetic evaluation -- no operation to be done but
the spaces around the value are dropped.

>
> jamie.

Tomi


Re: [PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD

2012-05-31 Thread Jani Nikula
On Wed, 30 May 2012, Tomi Ollila tomi.oll...@iki.fi wrote:
 On Wed, May 30 2012, Jameson Graef Rollins jroll...@finestructure.net wrote:

 On Wed, May 30 2012, Mike Kelly pi...@pioto.org wrote:
 FreeBSD's `wc -l` includes some white space in front of the number.
 Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures
 we do a proper numeric comparision, and in a portable way.

 Is there a way we can avoid adding another new test function here?  This
 new function is almost completely identical with the old one, except
 that it uses test .. -eq instead of [ .. =.  If the problem is just
 that the arguments occasionally contain superfluous spaces, I would
 rather see the existing function just strip the spaces.  Of maybe add an
 option to the test to ask for arithmetic rather than string comparison.
 That would be preferable to introducing an new function that is
 confusingly similar to an existing one.

 I liked Mike's suggestion as I also thought the options; stripping in
 test_expect_equal cannot be done as there might be whitespace differences
 which mean failure arguments to test_expect_equal cannot be given without
 quotes as variable might be split into multiple args. if test_expect_equal
 were changed to take comparison argument (like '-eq' or '=')  then all
 calls would need to be changes (and function name could be changed to
 something more generic...) None of these sounded as good options...

 But, there is at least one option more:

 test_expect_equal \
 -`notmuch search --output=messages ${SEARCH} | wc -l` \
 +$((`notmuch search --output=messages ${SEARCH} | wc -l`)) \
 `notmuch count --output=messages ${SEARCH}`

 this makes arithmetic evaluation -- no operation to be done but
 the spaces around the value are dropped.

But it's non-obvious. How about just adding '| tr -d  ' to the end and
be done with it?

J.




 jamie.

 Tomi
 ___
 notmuch mailing list
 notmuch@notmuchmail.org
 http://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD

2012-05-30 Thread Jameson Graef Rollins
On Wed, May 30 2012, Mike Kelly  wrote:
> FreeBSD's `wc -l` includes some white space in front of the number.
> Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures
> we do a proper numeric comparision, and in a portable way.

Is there a way we can avoid adding another new test function here?  This
new function is almost completely identical with the old one, except
that it uses "test .. -eq" instead of "[ .. =".  If the problem is just
that the arguments occasionally contain superfluous spaces, I would
rather see the existing function just strip the spaces.  Of maybe add an
option to the test to ask for arithmetic rather than string comparison.
That would be preferable to introducing an new function that is
confusingly similar to an existing one.

> +# Like test_expect_equal, but does a numeric comparision instead of a
> +# string comparision
> +test_expect_equal_num () {
> + exec 1>&6 2>&7  # Restore stdout and stderr
> + inside_subtest=
> + test "$#" = 3 && { prereq=$1; shift; } || prereq=
> + test "$#" = 2 ||
> + error "bug in the test script: not 2 or 3 parameters to 
> test_expect_equal"
> +
> + output="$1"
> + expected="$2"
> + if ! test_skip "$test_subtest_name"
> + then
> + if test "$output" -eq "$expected"
> + then
> + test_ok_ "$test_subtest_name"
> + else
> + test_failure_ "$test_subtest_name" "$output != 
> $expected"
> + fi
> + fi
> +}

Also, the new function is missing the diff output, which is important
for debugging, and the syntax is different from the standard we've been
using:

  if ...; then

We try to maintain syntax consistency across the code base.  Thanks.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



[PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD

2012-05-30 Thread Mike Kelly
FreeBSD's `wc -l` includes some white space in front of the number.
Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures
we do a proper numeric comparision, and in a portable way.
---
 test/count   |8 
 test/test-lib.sh |   22 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/test/count b/test/count
index 300b171..902c7c6 100755
--- a/test/count
+++ b/test/count
@@ -7,22 +7,22 @@ add_email_corpus
 SEARCH="\"*\""

 test_begin_subtest "message count is the default for notmuch count"
-test_expect_equal \
+test_expect_equal_num \
 "`notmuch search --output=messages ${SEARCH} | wc -l`" \
 "`notmuch count ${SEARCH}`"

 test_begin_subtest "message count with --output=messages"
-test_expect_equal \
+test_expect_equal_num \
 "`notmuch search --output=messages ${SEARCH} | wc -l`" \
 "`notmuch count --output=messages ${SEARCH}`"

 test_begin_subtest "thread count with --output=threads"
-test_expect_equal \
+test_expect_equal_num \
 "`notmuch search --output=threads ${SEARCH} | wc -l`" \
 "`notmuch count --output=threads ${SEARCH}`"

 test_begin_subtest "thread count is the default for notmuch search"
-test_expect_equal \
+test_expect_equal_num \
 "`notmuch search ${SEARCH} | wc -l`" \
 "`notmuch count --output=threads ${SEARCH}`"

diff --git a/test/test-lib.sh b/test/test-lib.sh
index da792b7..2ac92f7 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -512,6 +512,28 @@ test_expect_equal_file ()
 fi
 }

+# Like test_expect_equal, but does a numeric comparision instead of a
+# string comparision
+test_expect_equal_num () {
+   exec 1>&6 2>&7  # Restore stdout and stderr
+   inside_subtest=
+   test "$#" = 3 && { prereq=$1; shift; } || prereq=
+   test "$#" = 2 ||
+   error "bug in the test script: not 2 or 3 parameters to 
test_expect_equal"
+
+   output="$1"
+   expected="$2"
+   if ! test_skip "$test_subtest_name"
+   then
+   if test "$output" -eq "$expected"
+   then
+   test_ok_ "$test_subtest_name"
+   else
+   test_failure_ "$test_subtest_name" "$output != 
$expected"
+   fi
+   fi
+}
+
 test_emacs_expect_t () {
test "$#" = 2 && { prereq=$1; shift; } || prereq=
test "$#" = 1 ||
-- 
1.7.10.2



[PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD

2012-05-30 Thread Mike Kelly
FreeBSD's `wc -l` includes some white space in front of the number.
Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures
we do a proper numeric comparision, and in a portable way.
---
 test/count   |8 
 test/test-lib.sh |   22 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/test/count b/test/count
index 300b171..902c7c6 100755
--- a/test/count
+++ b/test/count
@@ -7,22 +7,22 @@ add_email_corpus
 SEARCH=\*\
 
 test_begin_subtest message count is the default for notmuch count
-test_expect_equal \
+test_expect_equal_num \
 `notmuch search --output=messages ${SEARCH} | wc -l` \
 `notmuch count ${SEARCH}`
 
 test_begin_subtest message count with --output=messages
-test_expect_equal \
+test_expect_equal_num \
 `notmuch search --output=messages ${SEARCH} | wc -l` \
 `notmuch count --output=messages ${SEARCH}`
 
 test_begin_subtest thread count with --output=threads
-test_expect_equal \
+test_expect_equal_num \
 `notmuch search --output=threads ${SEARCH} | wc -l` \
 `notmuch count --output=threads ${SEARCH}`
 
 test_begin_subtest thread count is the default for notmuch search
-test_expect_equal \
+test_expect_equal_num \
 `notmuch search ${SEARCH} | wc -l` \
 `notmuch count --output=threads ${SEARCH}`
 
diff --git a/test/test-lib.sh b/test/test-lib.sh
index da792b7..2ac92f7 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -512,6 +512,28 @@ test_expect_equal_file ()
 fi
 }
 
+# Like test_expect_equal, but does a numeric comparision instead of a
+# string comparision
+test_expect_equal_num () {
+   exec 16 27  # Restore stdout and stderr
+   inside_subtest=
+   test $# = 3  { prereq=$1; shift; } || prereq=
+   test $# = 2 ||
+   error bug in the test script: not 2 or 3 parameters to 
test_expect_equal
+
+   output=$1
+   expected=$2
+   if ! test_skip $test_subtest_name
+   then
+   if test $output -eq $expected
+   then
+   test_ok_ $test_subtest_name
+   else
+   test_failure_ $test_subtest_name $output != 
$expected
+   fi
+   fi
+}
+
 test_emacs_expect_t () {
test $# = 2  { prereq=$1; shift; } || prereq=
test $# = 1 ||
-- 
1.7.10.2

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD

2012-05-30 Thread Jameson Graef Rollins
On Wed, May 30 2012, Mike Kelly pi...@pioto.org wrote:
 FreeBSD's `wc -l` includes some white space in front of the number.
 Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures
 we do a proper numeric comparision, and in a portable way.

Is there a way we can avoid adding another new test function here?  This
new function is almost completely identical with the old one, except
that it uses test .. -eq instead of [ .. =.  If the problem is just
that the arguments occasionally contain superfluous spaces, I would
rather see the existing function just strip the spaces.  Of maybe add an
option to the test to ask for arithmetic rather than string comparison.
That would be preferable to introducing an new function that is
confusingly similar to an existing one.

 +# Like test_expect_equal, but does a numeric comparision instead of a
 +# string comparision
 +test_expect_equal_num () {
 + exec 16 27  # Restore stdout and stderr
 + inside_subtest=
 + test $# = 3  { prereq=$1; shift; } || prereq=
 + test $# = 2 ||
 + error bug in the test script: not 2 or 3 parameters to 
 test_expect_equal
 +
 + output=$1
 + expected=$2
 + if ! test_skip $test_subtest_name
 + then
 + if test $output -eq $expected
 + then
 + test_ok_ $test_subtest_name
 + else
 + test_failure_ $test_subtest_name $output != 
 $expected
 + fi
 + fi
 +}

Also, the new function is missing the diff output, which is important
for debugging, and the syntax is different from the standard we've been
using:

  if ...; then

We try to maintain syntax consistency across the code base.  Thanks.

jamie.


pgpp4acYmcbcW.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD

2012-05-30 Thread Tomi Ollila
On Wed, May 30 2012, Jameson Graef Rollins jroll...@finestructure.net wrote:

 On Wed, May 30 2012, Mike Kelly pi...@pioto.org wrote:
 FreeBSD's `wc -l` includes some white space in front of the number.
 Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures
 we do a proper numeric comparision, and in a portable way.

 Is there a way we can avoid adding another new test function here?  This
 new function is almost completely identical with the old one, except
 that it uses test .. -eq instead of [ .. =.  If the problem is just
 that the arguments occasionally contain superfluous spaces, I would
 rather see the existing function just strip the spaces.  Of maybe add an
 option to the test to ask for arithmetic rather than string comparison.
 That would be preferable to introducing an new function that is
 confusingly similar to an existing one.

I liked Mike's suggestion as I also thought the options; stripping in
test_expect_equal cannot be done as there might be whitespace differences
which mean failure arguments to test_expect_equal cannot be given without
quotes as variable might be split into multiple args. if test_expect_equal
were changed to take comparison argument (like '-eq' or '=')  then all
calls would need to be changes (and function name could be changed to
something more generic...) None of these sounded as good options...

But, there is at least one option more:

test_expect_equal \
-`notmuch search --output=messages ${SEARCH} | wc -l` \
+$((`notmuch search --output=messages ${SEARCH} | wc -l`)) \
`notmuch count --output=messages ${SEARCH}`

this makes arithmetic evaluation -- no operation to be done but
the spaces around the value are dropped.


 jamie.

Tomi
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch