[PATCH 3/3] test: Add address cleaning tests.
authorDavid Edmondson <dme@dme.org>
Thu, 19 Jan 2012 12:54:03 +0000 (12:54 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:42:41 +0000 (09:42 -0800)
61/d561859473cb0bb990ede7f243f61349cd010c [new file with mode: 0644]

diff --git a/61/d561859473cb0bb990ede7f243f61349cd010c b/61/d561859473cb0bb990ede7f243f61349cd010c
new file mode 100644 (file)
index 0000000..f9a289c
--- /dev/null
@@ -0,0 +1,188 @@
+Return-Path: <dme@dme.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 0BFAC431FBD\r
+       for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 04:54:12 -0800 (PST)\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 CA0zrFlwPsFe for <notmuch@notmuchmail.org>;\r
+       Thu, 19 Jan 2012 04:54:11 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id D5A1C431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 04:54:10 -0800 (PST)\r
+Received: by mail-we0-f181.google.com with SMTP id p13so2507773wer.26\r
+       for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 04:54:10 -0800 (PST)\r
+Received: by 10.216.136.152 with SMTP id w24mr5289114wei.50.1326977650539;\r
+       Thu, 19 Jan 2012 04:54:10 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+       (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+       by mx.google.com with ESMTPS id ex2sm65943483wib.1.2012.01.19.04.54.07\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 19 Jan 2012 04:54:08 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id 15CBF9FEC4; Thu, 19 Jan 2012 12:54:06 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] test: Add address cleaning tests.\r
+Date: Thu, 19 Jan 2012 12:54:03 +0000\r
+Message-Id: <1326977643-19792-3-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1326977643-19792-1-git-send-email-dme@dme.org>\r
+References: <yf639bcarcs.fsf@taco2.nixu.fi>\r
+       <1326977643-19792-1-git-send-email-dme@dme.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\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: Thu, 19 Jan 2012 12:54:12 -0000\r
+\r
+Including some more test framework in test-lib.el.\r
+---\r
+ test/emacs-address-cleaning.el |   29 +++++++++++++++++++++++++++++\r
+ test/emacs-address-cleaning.sh |   12 ++++++++++++\r
+ test/notmuch-test              |    1 +\r
+ test/test-lib.el               |   30 ++++++++++++++++++++++++++++++\r
+ 4 files changed, 72 insertions(+), 0 deletions(-)\r
+ create mode 100644 test/emacs-address-cleaning.el\r
+ create mode 100755 test/emacs-address-cleaning.sh\r
+\r
+diff --git a/test/emacs-address-cleaning.el b/test/emacs-address-cleaning.el\r
+new file mode 100644\r
+index 0000000..59e8d92\r
+--- /dev/null\r
++++ b/test/emacs-address-cleaning.el\r
+@@ -0,0 +1,29 @@\r
++(defun notmuch-test-address-cleaning-1 ()\r
++  (notmuch-test-compare (notmuch-show-clean-address "dme@dme.org")\r
++                      "dme@dme.org"))\r
++\r
++(defun notmuch-test-address-cleaning-2 ()\r
++  (let* ((input '("foo@bar.com"\r
++                "<foo@bar.com>"\r
++                "Foo Bar <foo@bar.com>"\r
++                "foo@bar.com <foo@bar.com>"\r
++                "\"Foo Bar\" <foo@bar.com>"))\r
++       (expected '("foo@bar.com"\r
++                   "foo@bar.com"\r
++                   "Foo Bar <foo@bar.com>"\r
++                   "foo@bar.com"\r
++                   "Foo Bar <foo@bar.com>"))\r
++       (output (mapcar #'notmuch-show-clean-address input)))\r
++    (notmuch-test-compare output expected)))\r
++\r
++(defun notmuch-test-address-cleaning-3 ()\r
++  (let* ((input '("ДБ <db-uknot@stop.me.uk>"\r
++                "foo (at home) <foo@bar.com>"\r
++                "foo [at home] <foo@bar.com>"\r
++                "Foo Bar"))\r
++       (expected '("ДБ <db-uknot@stop.me.uk>"\r
++                   "foo (at home) <foo@bar.com>"\r
++                   "foo [at home] <foo@bar.com>"\r
++                   "Foo Bar"))\r
++       (output (mapcar #'notmuch-show-clean-address input)))\r
++    (notmuch-test-compare output expected)))\r
+diff --git a/test/emacs-address-cleaning.sh b/test/emacs-address-cleaning.sh\r
+new file mode 100755\r
+index 0000000..1a6eff5\r
+--- /dev/null\r
++++ b/test/emacs-address-cleaning.sh\r
+@@ -0,0 +1,12 @@\r
++#!/usr/bin/env bash\r
++\r
++test_description="emacs address cleaning"\r
++. test-lib.sh\r
++\r
++for i in 1 2 3; do\r
++    test_begin_subtest "notmuch-test-address-clean-$i"\r
++    test_emacs_expect_t \\r
++      '(load "emacs-address-cleaning.el") (notmuch-test-address-cleaning-'$i')'\r
++done\r
++\r
++test_done\r
+diff --git a/test/notmuch-test b/test/notmuch-test\r
+index d034f99..3f1740c 100755\r
+--- a/test/notmuch-test\r
++++ b/test/notmuch-test\r
+@@ -53,6 +53,7 @@ TESTS="\r
+   hooks\r
+   argument-parsing\r
+   emacs-test-functions.sh\r
++  emacs-address-cleaning.sh\r
+ "\r
+ TESTS=${NOTMUCH_TESTS:=$TESTS}\r
\r
+diff --git a/test/test-lib.el b/test/test-lib.el\r
+index 1d51b8d..033270d 100644\r
+--- a/test/test-lib.el\r
++++ b/test/test-lib.el\r
+@@ -20,6 +20,8 @@\r
+ ;;\r
+ ;; Authors: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
\r
++(require 'cl) ;; This code is generally used uncompiled.\r
++\r
+ ;; `read-file-name' by default uses `completing-read' function to read\r
+ ;; user input.  It does not respect `standard-input' variable which we\r
+ ;; use in tests to provide user input.  So replace it with a plain\r
+@@ -77,6 +79,7 @@ nothing."\r
+ (add-hook-counter 'notmuch-hello-mode-hook)\r
+ (add-hook-counter 'notmuch-hello-refresh-hook)\r
\r
++\r
+ (defmacro notmuch-test-run-test (&rest body)\r
+   "Evaluate a BODY of test expressions and output the result."\r
+   `(with-temp-buffer\r
+@@ -85,3 +88,30 @@ nothing."\r
+                  result\r
+                (prin1-to-string result)))\r
+        (test-output))))\r
++\r
++;; Functions to help when writing tests:\r
++\r
++(defun notmuch-test-reporter (output expected)\r
++  "Report that the `output' does not match the `expected' result."\r
++  (concat "Expect:\t" (prin1-to-string expected) "\n"\r
++        "Output:\t" (prin1-to-string output) "\n"))\r
++\r
++(defun notmuch-test-unsimilar (output expected)\r
++  "`output' and `expected' are dissimilar. Show a summary of\r
++the differences, ignoring similarities."\r
++  (cond ((and (listp output)\r
++            (listp expected))\r
++       (apply #'concat (loop for o in output\r
++                             for e in expected\r
++                             if (not (equal o e))\r
++                             collect (notmuch-test-reporter o e))))\r
++\r
++      (t\r
++       ;; Catch all case.\r
++       (notmuch-test-reporter output expected))))\r
++\r
++(defun notmuch-test-compare (output expected)\r
++  "Compare `output' with `expected'. Report any discrepencies."\r
++  (if (equal output expected)\r
++      t\r
++    (notmuch-test-unsimilar output expected)))\r
+-- \r
+1.7.8.3\r
+\r