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 8EA4C421192 for ; Tue, 17 Jan 2012 06:07:14 -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 suQ2ib5OpIrE for ; Tue, 17 Jan 2012 06:07:12 -0800 (PST) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 44BA7429E2F for ; Tue, 17 Jan 2012 06:07:12 -0800 (PST) Received: by wibhr12 with SMTP id hr12so3471746wib.26 for ; Tue, 17 Jan 2012 06:07:11 -0800 (PST) Received: by 10.180.73.72 with SMTP id j8mr17867301wiv.2.1326809230987; Tue, 17 Jan 2012 06:07:10 -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 dr7sm13867947wib.3.2012.01.17.06.07.06 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Jan 2012 06:07:09 -0800 (PST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id A15DDA0501; Tue, 17 Jan 2012 14:07:05 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 3/3] test: Add address cleaning tests. Date: Tue, 17 Jan 2012 14:07:04 +0000 Message-Id: <1326809224-22673-3-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1326809224-22673-1-git-send-email-dme@dme.org> References: <87pqei327k.fsf@gmail.com> <1326809224-22673-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 14:07:15 -0000 Including some more test framework in test-lib.el. --- notmuch-test-address-cleaning-3 currently fails, in order that you can see the output format in that case. test/emacs-address-cleaning.el | 29 +++++++++++++++++++++++++++++ test/emacs-address-cleaning.sh | 12 ++++++++++++ test/notmuch-test | 1 + test/test-lib.el | 29 +++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 0 deletions(-) create mode 100644 test/emacs-address-cleaning.el create mode 100755 test/emacs-address-cleaning.sh diff --git a/test/emacs-address-cleaning.el b/test/emacs-address-cleaning.el new file mode 100644 index 0000000..59e8d92 --- /dev/null +++ b/test/emacs-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/emacs-address-cleaning.sh b/test/emacs-address-cleaning.sh new file mode 100755 index 0000000..1a6eff5 --- /dev/null +++ b/test/emacs-address-cleaning.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +test_description="emacs address cleaning" +. test-lib.sh + +for i in 1 2 3; do + test_begin_subtest "notmuch-test-address-clean-$i" + test_emacs_expect_t \ + '(load "emacs-address-cleaning.el") (notmuch-test-address-cleaning-'$i')' +done + +test_done diff --git a/test/notmuch-test b/test/notmuch-test index d034f99..3f1740c 100755 --- a/test/notmuch-test +++ b/test/notmuch-test @@ -53,6 +53,7 @@ TESTS=" hooks argument-parsing emacs-test-functions.sh + emacs-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