[PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD
authorMike Kelly <pioto@pioto.org>
Wed, 30 May 2012 07:02:02 +0000 (03:02 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:31 +0000 (09:47 -0800)
e3/5e738c08e6206f5d15170993d493e796089173 [new file with mode: 0644]

diff --git a/e3/5e738c08e6206f5d15170993d493e796089173 b/e3/5e738c08e6206f5d15170993d493e796089173
new file mode 100644 (file)
index 0000000..deb5e95
--- /dev/null
@@ -0,0 +1,142 @@
+Return-Path: <pioto@pioto.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A217E431FD2\r
+       for <notmuch@notmuchmail.org>; Wed, 30 May 2012 00:02:58 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 9bO3j2l6BRok for <notmuch@notmuchmail.org>;\r
+       Wed, 30 May 2012 00:02:57 -0700 (PDT)\r
+Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com\r
+       [209.85.220.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id F3C43431FAF\r
+       for <notmuch@notmuchmail.org>; Wed, 30 May 2012 00:02:55 -0700 (PDT)\r
+Received: by mail-vc0-f181.google.com with SMTP id f1so4187995vcb.26\r
+       for <notmuch@notmuchmail.org>; Wed, 30 May 2012 00:02:55 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
+       :x-gm-message-state;\r
+       bh=p6l7vxdTZnwwRJ6TCqtNq8A8oPuCnSvrVnR/UcLpeGg=;\r
+       b=gLaWg9Sle+lK/ESBPijfXa+fPfzhFB5Plyp0vFW2JIsR9DctwLu2c1pe8yO7kZQSud\r
+       ShOvZoGYlyWYdHQAtu8n2yZ7SyYSnGO+W3kZ4dsoj4nPFDbH5UVlf++0YRDCDuMTa4xk\r
+       k66A/g65GPfk1Q4Uvls7xMkCyFPwOijlZ1PWE8YipPmMFTMZRMRVzvZMaXzVIBq846rC\r
+       DXp651shmEKbtWOOySZsfe0zkzzqt+h4vpmEjBekC5RjgT7ZfrQBaP4qxuPhiFvYIzKh\r
+       7qdCrn9iF8lA6DYEPV4FyFaslFJB7bCf6aI5iiW562aLDAQWIGyCZcJ9q0vzOBpNjmUR\r
+       WSHQ==\r
+Received: by 10.52.90.199 with SMTP id by7mr13350786vdb.30.1338361375638;\r
+       Wed, 30 May 2012 00:02:55 -0700 (PDT)\r
+Received: from nas.home.pioto.org (pool-71-182-155-97.pitbpa.fios.verizon.net.\r
+       [71.182.155.97])\r
+       by mx.google.com with ESMTPS id d20sm28307480vde.20.2012.05.30.00.02.54\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Wed, 30 May 2012 00:02:55 -0700 (PDT)\r
+Received: by nas.home.pioto.org (Postfix, from userid 1001)\r
+       id 086F8287DC; Wed, 30 May 2012 03:02:53 -0400 (EDT)\r
+From: Mike Kelly <pioto@pioto.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 7/9] test/count: fix numeric comparision tests on FreeBSD\r
+Date: Wed, 30 May 2012 03:02:02 -0400\r
+Message-Id: <1338361324-57289-8-git-send-email-pioto@pioto.org>\r
+X-Mailer: git-send-email 1.7.10.2\r
+In-Reply-To: <1338361324-57289-1-git-send-email-pioto@pioto.org>\r
+References: <1338361324-57289-1-git-send-email-pioto@pioto.org>\r
+X-Gm-Message-State:\r
+ ALoCoQkXkPhyqBsZjex6ilBNRQykMsV/8h+cHpY3cACUC/1zxaQL6iKuPLkLKpYNFDJVFigN/8q0\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 30 May 2012 07:02:59 -0000\r
+\r
+FreeBSD's `wc -l` includes some white space in front of the number.\r
+Instead, we add a test_expect_equal_num() to test-lib.sh, which ensures\r
+we do a proper numeric comparision, and in a portable way.\r
+---\r
+ test/count       |    8 ++++----\r
+ test/test-lib.sh |   22 ++++++++++++++++++++++\r
+ 2 files changed, 26 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/test/count b/test/count\r
+index 300b171..902c7c6 100755\r
+--- a/test/count\r
++++ b/test/count\r
+@@ -7,22 +7,22 @@ add_email_corpus\r
+ SEARCH="\"*\""\r
+ \r
+ test_begin_subtest "message count is the default for notmuch count"\r
+-test_expect_equal \\r
++test_expect_equal_num \\r
+     "`notmuch search --output=messages ${SEARCH} | wc -l`" \\r
+     "`notmuch count ${SEARCH}`"\r
+ \r
+ test_begin_subtest "message count with --output=messages"\r
+-test_expect_equal \\r
++test_expect_equal_num \\r
+     "`notmuch search --output=messages ${SEARCH} | wc -l`" \\r
+     "`notmuch count --output=messages ${SEARCH}`"\r
+ \r
+ test_begin_subtest "thread count with --output=threads"\r
+-test_expect_equal \\r
++test_expect_equal_num \\r
+     "`notmuch search --output=threads ${SEARCH} | wc -l`" \\r
+     "`notmuch count --output=threads ${SEARCH}`"\r
+ \r
+ test_begin_subtest "thread count is the default for notmuch search"\r
+-test_expect_equal \\r
++test_expect_equal_num \\r
+     "`notmuch search ${SEARCH} | wc -l`" \\r
+     "`notmuch count --output=threads ${SEARCH}`"\r
+ \r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index da792b7..2ac92f7 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -512,6 +512,28 @@ test_expect_equal_file ()\r
+     fi\r
+ }\r
+ \r
++# Like test_expect_equal, but does a numeric comparision instead of a\r
++# string comparision\r
++test_expect_equal_num () {\r
++      exec 1>&6 2>&7          # Restore stdout and stderr\r
++      inside_subtest=\r
++      test "$#" = 3 && { prereq=$1; shift; } || prereq=\r
++      test "$#" = 2 ||\r
++      error "bug in the test script: not 2 or 3 parameters to test_expect_equal"\r
++\r
++      output="$1"\r
++      expected="$2"\r
++      if ! test_skip "$test_subtest_name"\r
++      then\r
++              if test "$output" -eq "$expected"\r
++              then\r
++                      test_ok_ "$test_subtest_name"\r
++              else\r
++                      test_failure_ "$test_subtest_name" "$output != $expected"\r
++              fi\r
++      fi\r
++}\r
++\r
+ test_emacs_expect_t () {\r
+       test "$#" = 2 && { prereq=$1; shift; } || prereq=\r
+       test "$#" = 1 ||\r
+-- \r
+1.7.10.2\r
+\r