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 886B241A549 for ; Thu, 25 Nov 2010 03:03:27 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 9asNrB98rMer for ; Thu, 25 Nov 2010 03:03:26 -0800 (PST) Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com [74.125.82.181]) by olra.theworths.org (Postfix) with ESMTP id 7DE71431FD0 for ; Thu, 25 Nov 2010 03:03:25 -0800 (PST) Received: by mail-wy0-f181.google.com with SMTP id 22so827352wyf.26 for ; Thu, 25 Nov 2010 03:03:25 -0800 (PST) Received: by 10.227.155.83 with SMTP id r19mr634010wbw.166.1290683004236; Thu, 25 Nov 2010 03:03:24 -0800 (PST) Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com [81.149.164.25]) by mx.google.com with ESMTPS id h29sm403035wbc.3.2010.11.25.03.03.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 25 Nov 2010 03:03:19 -0800 (PST) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id 985F359407A; Thu, 25 Nov 2010 10:59:20 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 3/3] test: Add ERT tests for Fcc determination. Date: Thu, 25 Nov 2010 10:59:10 +0000 Message-Id: <1290682750-30283-3-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1290632444-10046-1-git-send-email-cworth@cworth.org> References: <1290632444-10046-1-git-send-email-cworth@cworth.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, 25 Nov 2010 11:03:27 -0000 Add ERT tests to cover various settings of `notmuch-fcc-dirs'. --- emacs/notmuch-test.el | 96 ++++++++++++++++++++++++++++++++++ test/emacs-ert | 17 ++++++ test/emacs.expected-output/emacs-ert | 9 +++ 3 files changed, 122 insertions(+), 0 deletions(-) create mode 100644 emacs/notmuch-test.el create mode 100755 test/emacs-ert create mode 100644 test/emacs.expected-output/emacs-ert diff --git a/emacs/notmuch-test.el b/emacs/notmuch-test.el new file mode 100644 index 0000000..ac6e5a7 --- /dev/null +++ b/emacs/notmuch-test.el @@ -0,0 +1,96 @@ +;; notmuch-test.el --- ERT based tests for notmuch.el. +;; +;; Copyright © David Edmondson +;; +;; This file is part of Notmuch. +;; +;; Notmuch is free software: you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; Notmuch is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with Notmuch. If not, see . +;; +;; Authors: David Edmondson + +(require 'ert) + +;; + +(require 'notmuch-maildir-fcc) + +(ert-deftest notmuch-fcc-trivial () + "One Fcc folder." + (should (string= "sent" + (notmuch-fcc-determine-folder "sent" "foo@bar.baz")))) + +(ert-deftest notmuch-fcc-simple () + "Fcc folder matching single address." + (should (string= "sent" + (notmuch-fcc-determine-folder + '(("foo@bar.baz" . "sent")) + "foo@bar.baz")))) + +(ert-deftest notmuch-fcc-none () + "No matching Fcc folder." + (should (eq nil + (notmuch-fcc-determine-folder + '(("foo@bar.baz" . "sent")) + "not@bar.baz")))) + +(ert-deftest notmuch-fcc-multiple () + "Choose the correct folder from two options." + (let ((fcc-config '(("foo@bar.baz" . "foosent") + ("bar@bar.baz" . "barsent")))) + + (should (string= "foosent" + (notmuch-fcc-determine-folder + fcc-config "foo@bar.baz"))) + + (should (string= "barsent" + (notmuch-fcc-determine-folder + fcc-config "bar@bar.baz"))))) + +(ert-deftest notmuch-fcc-regexp () + "Allow a regexp in the `From' string." + (let ((fcc-config '(("foo@bar.baz" . "foosent") + (".*" . "barsent")))) + + (should (string= "foosent" + (notmuch-fcc-determine-folder + fcc-config "foo@bar.baz"))) + + (should (string= "barsent" + (notmuch-fcc-determine-folder + fcc-config "bar@bar.baz"))))) + +(ert-deftest notmuch-fcc-oldstyle () + "Raise an error for an old style configuration." + + ;; No match. + (should-error (notmuch-fcc-determine-folder + '("sent" ("not@bar.baz" . "foosent")) + "foo@bar.baz")) + ;; One match. + (should-error (notmuch-fcc-determine-folder + '("sent" ("not@bar.baz" . "foosent")) + "not@bar.baz"))) + + +;; + +(defun notmuch-test () + "Run the notmuch ERT tests." + (interactive) + + (ert t)) + +(defun notmuch-test-batch () + "Run the notmuch ERT tests in batch mode." + (ert-run-tests-batch-and-exit)) diff --git a/test/emacs-ert b/test/emacs-ert new file mode 100755 index 0000000..4a45a66 --- /dev/null +++ b/test/emacs-ert @@ -0,0 +1,17 @@ +#!/bin/bash +test_description="emacs interface (ert)" +. test-lib.sh + +EXPECTED=../emacs.expected-output + +test_begin_subtest "Emacs tests using ert" +output=$(emacs \ + --batch --no-init-file --no-site-file \ + --directory ../../emacs --directory ../ert \ + --load notmuch-test.el \ + --eval "(notmuch-test-batch)" \ + 2>&1 | sed -e 's/[0-9][0-9]*-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]*/today/g') +expected=$(cat $EXPECTED/emacs-ert) +test_expect_equal "$output" "$expected" + +test_done diff --git a/test/emacs.expected-output/emacs-ert b/test/emacs.expected-output/emacs-ert new file mode 100644 index 0000000..50f592b --- /dev/null +++ b/test/emacs.expected-output/emacs-ert @@ -0,0 +1,9 @@ +Running 6 tests (today) + passed 1/6 notmuch-fcc-multiple + passed 2/6 notmuch-fcc-none + passed 3/6 notmuch-fcc-oldstyle + passed 4/6 notmuch-fcc-regexp + passed 5/6 notmuch-fcc-simple + passed 6/6 notmuch-fcc-trivial + +Ran 6 tests, 6 results as expected (today) -- 1.7.2.3