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

Jameson Graef Rollins jrollins at finestructure.net
Wed May 30 13:28:37 PDT 2012


On Wed, May 30 2012, Mike Kelly <pioto at 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 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: <http://notmuchmail.org/pipermail/notmuch/attachments/20120530/02e1f8d9/attachment.pgp>


More information about the notmuch mailing list