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 873A742119D for ; Tue, 17 Jan 2012 04:53:01 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 YAfnGIaQRHs8 for ; Tue, 17 Jan 2012 04:52:59 -0800 (PST) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 4EAD4421195 for ; Tue, 17 Jan 2012 04:52:51 -0800 (PST) Received: by werp13 with SMTP id p13so322385wer.26 for ; Tue, 17 Jan 2012 04:52:50 -0800 (PST) Received: by 10.216.133.29 with SMTP id p29mr6905304wei.49.1326804768133; Tue, 17 Jan 2012 04:52:48 -0800 (PST) Received: from hotblack-desiato.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25]) by mx.google.com with ESMTPS id em13sm16621693wid.7.2012.01.17.04.52.43 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Jan 2012 04:52:43 -0800 (PST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id 04BAAA0501; Tue, 17 Jan 2012 12:52:42 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 2/4] test: Add address cleaning tests. Date: Tue, 17 Jan 2012 12:52:26 +0000 Message-Id: <1326804748-8989-3-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1326804748-8989-1-git-send-email-dme@dme.org> References: <1326804748-8989-1-git-send-email-dme@dme.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Tue, 17 Jan 2012 12:53:02 -0000 Including some more test framework in test-lib.el. --- test/address-cleaning.el | 29 +++++++++++++++++++++++++++++ test/address-cleaning.sh | 11 +++++++++++ test/notmuch-test | 1 + test/test-lib.el | 29 +++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 0 deletions(-) create mode 100644 test/address-cleaning.el create mode 100755 test/address-cleaning.sh diff --git a/test/address-cleaning.el b/test/address-cleaning.el new file mode 100644 index 0000000..59e8d92 --- /dev/null +++ b/test/address-cleaning.el @@ -0,0 +1,29 @@ +(defun notmuch-test-address-cleaning-1 () + (notmuch-test-compare (notmuch-show-clean-address "dme@dme.org") + "dme@dme.org")) + +(defun notmuch-test-address-cleaning-2 () + (let* ((input '("foo@bar.com" + "" + "Foo Bar " + "foo@bar.com " + "\"Foo Bar\" ")) + (expected '("foo@bar.com" + "foo@bar.com" + "Foo Bar " + "foo@bar.com" + "Foo Bar ")) + (output (mapcar #'notmuch-show-clean-address input))) + (notmuch-test-compare output expected))) + +(defun notmuch-test-address-cleaning-3 () + (let* ((input '("ДБ " + "foo (at home) " + "foo [at home] " + "Foo Bar")) + (expected '("ДБ " + "foo (at home) " + "foo [at home] " + "Foo Bar")) + (output (mapcar #'notmuch-show-clean-address input))) + (notmuch-test-compare output expected))) diff --git a/test/address-cleaning.sh b/test/address-cleaning.sh new file mode 100755 index 0000000..7ec011a --- /dev/null +++ b/test/address-cleaning.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +test_description="emacs address cleaning" +. test-lib.sh + +for i in 1 2 3; do + test_emacs_expect_t "notmuch-test-address-clean-$i" \ + '(load "address-cleaning.el") (notmuch-test-address-cleaning-'$i')' +done + +test_done diff --git a/test/notmuch-test b/test/notmuch-test index d034f99..7768c32 100755 --- a/test/notmuch-test +++ b/test/notmuch-test @@ -53,6 +53,7 @@ TESTS=" hooks argument-parsing emacs-test-functions.sh + address-cleaning.sh " TESTS=${NOTMUCH_TESTS:=$TESTS} diff --git a/test/test-lib.el b/test/test-lib.el index 3b817c3..cf8a46d 100644 --- a/test/test-lib.el +++ b/test/test-lib.el @@ -20,6 +20,8 @@ ;; ;; Authors: Dmitry Kurochkin +(require 'cl) ;; This code is generally used uncompiled. + ;; `read-file-name' by default uses `completing-read' function to read ;; user input. It does not respect `standard-input' variable which we ;; use in tests to provide user input. So replace it with a plain @@ -76,3 +78,30 @@ nothing." (add-hook-counter 'notmuch-hello-mode-hook) (add-hook-counter 'notmuch-hello-refresh-hook) + +;; Functions to help when writing tests: + +(defun notmuch-test-reporter (output expected) + "Report that the `output' does not match the `expected' result." + (concat "Expect:\t" (prin1-to-string expected) "\n" + "Output:\t" (prin1-to-string output) "\n")) + +(defun notmuch-test-unsimilar (output expected) + "`output' and `expected' are dissimilar. Show a summary of +the differences, ignoring similarities." + (cond ((and (listp output) + (listp expected)) + (apply #'concat (loop for o in output + for e in expected + if (not (equal o e)) + collect (notmuch-test-reporter o e)))) + + (t + ;; Catch all case. + (notmuch-test-reporter output expected)))) + +(defun notmuch-test-compare (output expected) + "Compare `output' with `expected'. Report any discrepencies." + (if (equal output expected) + t + (notmuch-test-unsimilar output expected))) -- 1.7.7.3