From 213d400174a3e60ddc830326f6f9e3d35de8b2aa Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Thu, 31 May 2012 13:28:37 +1700 Subject: [PATCH] Re: [PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD --- 8c/c11535ce704c9ac6be47418874fe724cd2136b | 127 ++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 8c/c11535ce704c9ac6be47418874fe724cd2136b diff --git a/8c/c11535ce704c9ac6be47418874fe724cd2136b b/8c/c11535ce704c9ac6be47418874fe724cd2136b new file mode 100644 index 000000000..8e7e3ede4 --- /dev/null +++ b/8c/c11535ce704c9ac6be47418874fe724cd2136b @@ -0,0 +1,127 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id EAADB431FB6 + for ; Wed, 30 May 2012 13:28:43 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.29 +X-Spam-Level: +X-Spam-Status: No, score=-2.29 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3, T_MIME_NO_TEXT=0.01] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id GJep2InkF3P9 for ; + Wed, 30 May 2012 13:28:43 -0700 (PDT) +Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu + [131.215.239.19]) + by olra.theworths.org (Postfix) with ESMTP id 54468431FAF + for ; Wed, 30 May 2012 13:28:43 -0700 (PDT) +Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1]) + by earth-doxen-postvirus (Postfix) with ESMTP id DB12466E012C; + Wed, 30 May 2012 13:28:42 -0700 (PDT) +X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new +Received: from finestructure.net (m70.ligo.caltech.edu [131.215.115.170]) + (Authenticated sender: jrollins) + by earth-doxen-submit (Postfix) with ESMTP id EE36B66E01A4; + Wed, 30 May 2012 13:28:39 -0700 (PDT) +Received: by finestructure.net (Postfix, from userid 1000) + id CF9221D3; Wed, 30 May 2012 13:28:39 -0700 (PDT) +From: Jameson Graef Rollins +To: Mike Kelly , notmuch@notmuchmail.org +Subject: Re: [PATCH v2 7/9] test/count: fix numeric comparision tests on + FreeBSD +In-Reply-To: <1338361324-57289-8-git-send-email-pioto@pioto.org> +References: <1338361324-57289-1-git-send-email-pioto@pioto.org> + <1338361324-57289-8-git-send-email-pioto@pioto.org> +User-Agent: Notmuch/0.13+24~g16915cd (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Wed, 30 May 2012 13:28:37 -0700 +Message-ID: <877gvtxvka.fsf@servo.finestructure.net> +MIME-Version: 1.0 +Content-Type: multipart/signed; boundary="=-=-="; + micalg=pgp-sha256; protocol="application/pgp-signature" +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Wed, 30 May 2012 20:28:44 -0000 + +--=-=-= + +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. + +--=-=-= +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.12 (GNU/Linux) + +iQIcBAEBCAAGBQJPxoL1AAoJEO00zqvie6q8y04P/Av7haRAPhHgXVkRR1kJVnom +CIoEpbKq6yHz8M9dYyNpZ/zz8vFvjvZm6JghKkiHKPz1FXjY25GBjM2jeyxXVZ46 +xQ8IYT6K8GYfiRLKGMUZJLc6OXETKcHxsGRIzGP+rSsAOHWss3lKJxlJutrfz5rI +pZuo4m2fKiYm9Qiiu1V2/s2xWtD0ZGftf3zi/SetkYTHNhSNN/gi57SxGfb0I7bs +/ed0uDYLNPpbm+dRP/DnsLOFGbeCDRz5tMGa1zeKgfg3oAvzPwGrjYwn+HKVkloh +Xsk1sgswZSE0z08xi0w5i6l0aDjXE9Z11hT15T3mwzLmjkpNJOGCl8Mi3D45+PJa +XIPr6bTmEspPQq22ZANcKTT324597ER0SZR5tCCTOpaPDU6GmahxwocUonNZQWq+ +D0Oamy9qInDQJJ+eDHX2xjSr6/6X6yi2gT9bz2z71hO2xN0dtTgyNs9DdUZwBjeR +bJ5MR56o85xZzo2Eml30aZa9ujgbW28HVCvrjh3jEdoqb/blevCGqOXs63brwTLX +xqCpDMCYPKbMe1tU3i5qiPAHCd3VJftuYAVTo3QhPRWS/5cmOD/eAgyGsW/G7NNo +YzgmNMz/NCqGm/Hn1aLhGLdKdnAzUZNF5PlYatzwTvo/wS9ZU4XWs6LnlUXTkaBI +gvYA2B7ojIgiDLzgUK73 +=dKfi +-----END PGP SIGNATURE----- +--=-=-=-- -- 2.26.2