From 70b59a1ac0417a3a664cee572b9074a3fd562664 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Thu, 31 May 2012 00:00:50 +0300 Subject: [PATCH] Re: [PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD --- bd/16e2493bb836f919027f7d60e7609f1042f933 | 91 +++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 bd/16e2493bb836f919027f7d60e7609f1042f933 diff --git a/bd/16e2493bb836f919027f7d60e7609f1042f933 b/bd/16e2493bb836f919027f7d60e7609f1042f933 new file mode 100644 index 000000000..a3794f52c --- /dev/null +++ b/bd/16e2493bb836f919027f7d60e7609f1042f933 @@ -0,0 +1,91 @@ +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 55361431FB6 + for ; Wed, 30 May 2012 14:00:41 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 533eKh9XvcsH for ; + Wed, 30 May 2012 14:00:40 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 5A4BB431FAF + for ; Wed, 30 May 2012 14:00:40 -0700 (PDT) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 15343100642; Thu, 31 May 2012 00:00:50 +0300 (EEST) +From: Tomi Ollila +To: Jameson Graef Rollins , + Mike Kelly , notmuch@notmuchmail.org +Subject: Re: [PATCH v2 7/9] test/count: fix numeric comparision tests on + FreeBSD +In-Reply-To: <877gvtxvka.fsf@servo.finestructure.net> +References: <1338361324-57289-1-git-send-email-pioto@pioto.org> + <1338361324-57289-8-git-send-email-pioto@pioto.org> + <877gvtxvka.fsf@servo.finestructure.net> +User-Agent: Notmuch/0.13+29~g3c353b7 (http://notmuchmail.org) Emacs/23.1.1 + (x86_64-redhat-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +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 21:00:41 -0000 + +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 -- 2.26.2