[PATCH 3/3] test: Add ERT tests for Fcc determination.

David Edmondson dme at dme.org
Thu Nov 25 02:59:10 PST 2010


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 at 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 at bar.baz"))))
+
+(ert-deftest notmuch-fcc-simple ()
+  "Fcc folder matching single address."
+  (should (string= "sent"
+		   (notmuch-fcc-determine-folder
+		    '(("foo at bar.baz" . "sent"))
+		    "foo at bar.baz"))))
+
+(ert-deftest notmuch-fcc-none ()
+  "No matching Fcc folder."
+  (should (eq nil
+	      (notmuch-fcc-determine-folder
+	       '(("foo at bar.baz" . "sent"))
+	       "not at bar.baz"))))
+
+(ert-deftest notmuch-fcc-multiple ()
+  "Choose the correct folder from two options."
+  (let ((fcc-config '(("foo at bar.baz" . "foosent")
+		      ("bar at bar.baz" . "barsent"))))
+
+    (should (string= "foosent"
+		     (notmuch-fcc-determine-folder
+		      fcc-config "foo at bar.baz")))
+
+    (should (string= "barsent"
+		     (notmuch-fcc-determine-folder
+		      fcc-config "bar at bar.baz")))))
+
+(ert-deftest notmuch-fcc-regexp ()
+  "Allow a regexp in the `From' string."
+  (let ((fcc-config '(("foo at bar.baz" . "foosent")
+		      (".*" . "barsent"))))
+
+    (should (string= "foosent"
+		     (notmuch-fcc-determine-folder
+		      fcc-config "foo at bar.baz")))
+		     
+    (should (string= "barsent"
+		     (notmuch-fcc-determine-folder
+		      fcc-config "bar at 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 at bar.baz" . "foosent"))
+		 "foo at bar.baz"))
+  ;; One match.
+  (should-error (notmuch-fcc-determine-folder
+		 '("sent" ("not at bar.baz" . "foosent"))
+		 "not at 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



More information about the notmuch mailing list