From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH 3/3] test: Add ERT tests for Fcc determination.
Date: Thu, 25 Nov 2010 10:59:10 +0000 [thread overview]
Message-ID: <1290682750-30283-3-git-send-email-dme@dme.org> (raw)
In-Reply-To: <1290632444-10046-1-git-send-email-cworth@cworth.org>
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 <http://www.gnu.org/licenses/>.
+;;
+;; Authors: David Edmondson <dme@dme.org>
+
+(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
prev parent reply other threads:[~2010-11-25 11:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-24 21:00 [PATCH] Workaround broken check for old-style notmuch-fcc-dirs Carl Worth
2010-11-25 10:59 ` [PATCH 1/3] test: Add ERT for emacs testing David Edmondson
2010-11-25 12:02 ` David Edmondson
2010-11-25 14:09 ` [PATCH] test: Add some more emacs tests David Edmondson
2010-11-25 10:59 ` [PATCH 2/3] emacs: Fix Fcc generation David Edmondson
2010-11-25 10:59 ` David Edmondson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1290682750-30283-3-git-send-email-dme@dme.org \
--to=dme@dme.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).