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 0BFAC431FBD for ; Thu, 19 Jan 2012 04:54:12 -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 CA0zrFlwPsFe for ; Thu, 19 Jan 2012 04:54:11 -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 D5A1C431FAE for ; Thu, 19 Jan 2012 04:54:10 -0800 (PST) Received: by mail-we0-f181.google.com with SMTP id p13so2507773wer.26 for ; Thu, 19 Jan 2012 04:54:10 -0800 (PST) Received: by 10.216.136.152 with SMTP id w24mr5289114wei.50.1326977650539; Thu, 19 Jan 2012 04:54: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 ex2sm65943483wib.1.2012.01.19.04.54.07 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Jan 2012 04:54:08 -0800 (PST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id 15CBF9FEC4; Thu, 19 Jan 2012 12:54:06 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 3/3] test: Add address cleaning tests. Date: Thu, 19 Jan 2012 12:54:03 +0000 Message-Id: <1326977643-19792-3-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1326977643-19792-1-git-send-email-dme@dme.org> References: <1326977643-19792-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: Thu, 19 Jan 2012 12:54:12 -0000 Including some more test framework in test-lib.el. --- test/emacs-address-cleaning.el | 29 +++++++++++++++++++++++++++++ test/emacs-address-cleaning.sh | 12 ++++++++++++ test/notmuch-test | 1 + test/test-lib.el | 30 ++++++++++++++++++++++++++++++ 4 files changed, 72 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 1d51b8d..033270d 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 @@ -77,6 +79,7 @@ nothing." (add-hook-counter 'notmuch-hello-mode-hook) (add-hook-counter 'notmuch-hello-refresh-hook) + (defmacro notmuch-test-run-test (&rest body) "Evaluate a BODY of test expressions and output the result." `(with-temp-buffer @@ -85,3 +88,30 @@ nothing." result (prin1-to-string result))) (test-output)))) + +;; 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.8.3