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

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

Date: Wed, 30 May 2012 13:28:37 -0700

To: Mike Kelly, notmuch@notmuchmail.org

Cc:

From: Jameson Graef Rollins


On Wed, May 30 2012, Mike Kelly <pioto@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.
part-000.sig (application/pgp-signature)

Thread: