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 EA5CB429E35 for ; Tue, 17 Jan 2012 05:12:55 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 2US1H-xAwF4F for ; Tue, 17 Jan 2012 05:12:55 -0800 (PST) Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 120DA429E2F for ; Tue, 17 Jan 2012 05:12:54 -0800 (PST) Received: by bkty12 with SMTP id y12so517886bkt.26 for ; Tue, 17 Jan 2012 05:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type:content-transfer-encoding; bh=QVmeDejrn907aMVyvcLo8AvIBWjpT3KpdVoyDwkdNhw=; b=ZAcuF1LfH7ebvZfwaqycWox/oTp2E38zhvBVwRAacHMhsBsDPvNOTjr1uECH0bblTE jkTflgKhHS1K4nbseX+GKLTlCFaoRAQouQmLQoUklnVc7Ehe504CMDrpSS9WUOc2iF4A wZ4T9nV9jBKPey0w2V/ef7GRTiTSrrbF8MtcE= Received: by 10.204.151.195 with SMTP id d3mr6550908bkw.73.1326805973640; Tue, 17 Jan 2012 05:12:53 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id jt2sm47139358bkb.1.2012.01.17.05.12.52 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Jan 2012 05:12:53 -0800 (PST) From: Dmitry Kurochkin To: David Edmondson , notmuch@notmuchmail.org Subject: Re: [PATCH 2/4] test: Add address cleaning tests. In-Reply-To: <1326804748-8989-3-git-send-email-dme@dme.org> References: <1326804748-8989-1-git-send-email-dme@dme.org> <1326804748-8989-3-git-send-email-dme@dme.org> User-Agent: Notmuch/0.11+73~g8a5402e (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Tue, 17 Jan 2012 17:11:58 +0400 Message-ID: <87mx9m323l.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 13:12:56 -0000 On Tue, 17 Jan 2012 12:52:26 +0000, David Edmondson wrote: > 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 >=20 Since test/ directory is used for all kind of tests not just Emacs UI-specific, so I think address-cleaning.* files should be emacs-address-cleaning. Regards, Dmitry > 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 '("=D0=94=D0=91 " > + "foo (at home) " > + "foo [at home] " > + "Foo Bar")) > + (expected '("=D0=94=D0=91 " > + "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=3D"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=3D" > hooks > argument-parsing > emacs-test-functions.sh > + address-cleaning.sh > " > TESTS=3D${NOTMUCH_TESTS:=3D$TESTS} >=20=20 > 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 >=20=20 > +(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." >=20=20 > (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))) > --=20 > 1.7.7.3 >=20 > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch