Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / de / 6d600c085cb2777198fd2c397d5490af713ade
1 Return-Path: <dme@dme.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 886B241A549\r
6         for <notmuch@notmuchmail.org>; Thu, 25 Nov 2010 03:03:27 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 9asNrB98rMer for <notmuch@notmuchmail.org>;\r
16         Thu, 25 Nov 2010 03:03:26 -0800 (PST)\r
17 Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com\r
18         [74.125.82.181])\r
19         by olra.theworths.org (Postfix) with ESMTP id 7DE71431FD0\r
20         for <notmuch@notmuchmail.org>; Thu, 25 Nov 2010 03:03:25 -0800 (PST)\r
21 Received: by mail-wy0-f181.google.com with SMTP id 22so827352wyf.26\r
22         for <notmuch@notmuchmail.org>; Thu, 25 Nov 2010 03:03:25 -0800 (PST)\r
23 Received: by 10.227.155.83 with SMTP id r19mr634010wbw.166.1290683004236;\r
24         Thu, 25 Nov 2010 03:03:24 -0800 (PST)\r
25 Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com\r
26         [81.149.164.25])\r
27         by mx.google.com with ESMTPS id h29sm403035wbc.3.2010.11.25.03.03.18\r
28         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
29         Thu, 25 Nov 2010 03:03:19 -0800 (PST)\r
30 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
31         id 985F359407A; Thu, 25 Nov 2010 10:59:20 +0000 (GMT)\r
32 From: David Edmondson <dme@dme.org>\r
33 To: notmuch@notmuchmail.org\r
34 Subject: [PATCH 3/3] test: Add ERT tests for Fcc determination.\r
35 Date: Thu, 25 Nov 2010 10:59:10 +0000\r
36 Message-Id: <1290682750-30283-3-git-send-email-dme@dme.org>\r
37 X-Mailer: git-send-email 1.7.2.3\r
38 In-Reply-To: <1290632444-10046-1-git-send-email-cworth@cworth.org>\r
39 References: <1290632444-10046-1-git-send-email-cworth@cworth.org>\r
40 MIME-Version: 1.0\r
41 Content-Type: text/plain; charset=UTF-8\r
42 Content-Transfer-Encoding: 8bit\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Thu, 25 Nov 2010 11:03:27 -0000\r
56 \r
57 Add ERT tests to cover various settings of `notmuch-fcc-dirs'.\r
58 ---\r
59  emacs/notmuch-test.el                |   96 ++++++++++++++++++++++++++++++++++\r
60  test/emacs-ert                       |   17 ++++++\r
61  test/emacs.expected-output/emacs-ert |    9 +++\r
62  3 files changed, 122 insertions(+), 0 deletions(-)\r
63  create mode 100644 emacs/notmuch-test.el\r
64  create mode 100755 test/emacs-ert\r
65  create mode 100644 test/emacs.expected-output/emacs-ert\r
66 \r
67 diff --git a/emacs/notmuch-test.el b/emacs/notmuch-test.el\r
68 new file mode 100644\r
69 index 0000000..ac6e5a7\r
70 --- /dev/null\r
71 +++ b/emacs/notmuch-test.el\r
72 @@ -0,0 +1,96 @@\r
73 +;; notmuch-test.el --- ERT based tests for notmuch.el.\r
74 +;;\r
75 +;; Copyright © David Edmondson\r
76 +;;\r
77 +;; This file is part of Notmuch.\r
78 +;;\r
79 +;; Notmuch is free software: you can redistribute it and/or modify it\r
80 +;; under the terms of the GNU General Public License as published by\r
81 +;; the Free Software Foundation, either version 3 of the License, or\r
82 +;; (at your option) any later version.\r
83 +;;\r
84 +;; Notmuch is distributed in the hope that it will be useful, but\r
85 +;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
86 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
87 +;; General Public License for more details.\r
88 +;;\r
89 +;; You should have received a copy of the GNU General Public License\r
90 +;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
91 +;;\r
92 +;; Authors: David Edmondson <dme@dme.org>\r
93 +\r
94 +(require 'ert)\r
95 +\r
96 +;;\r
97 +\r
98 +(require 'notmuch-maildir-fcc)\r
99 +\r
100 +(ert-deftest notmuch-fcc-trivial ()\r
101 +  "One Fcc folder."\r
102 +  (should (string= "sent"\r
103 +                  (notmuch-fcc-determine-folder "sent" "foo@bar.baz"))))\r
104 +\r
105 +(ert-deftest notmuch-fcc-simple ()\r
106 +  "Fcc folder matching single address."\r
107 +  (should (string= "sent"\r
108 +                  (notmuch-fcc-determine-folder\r
109 +                   '(("foo@bar.baz" . "sent"))\r
110 +                   "foo@bar.baz"))))\r
111 +\r
112 +(ert-deftest notmuch-fcc-none ()\r
113 +  "No matching Fcc folder."\r
114 +  (should (eq nil\r
115 +             (notmuch-fcc-determine-folder\r
116 +              '(("foo@bar.baz" . "sent"))\r
117 +              "not@bar.baz"))))\r
118 +\r
119 +(ert-deftest notmuch-fcc-multiple ()\r
120 +  "Choose the correct folder from two options."\r
121 +  (let ((fcc-config '(("foo@bar.baz" . "foosent")\r
122 +                     ("bar@bar.baz" . "barsent"))))\r
123 +\r
124 +    (should (string= "foosent"\r
125 +                    (notmuch-fcc-determine-folder\r
126 +                     fcc-config "foo@bar.baz")))\r
127 +\r
128 +    (should (string= "barsent"\r
129 +                    (notmuch-fcc-determine-folder\r
130 +                     fcc-config "bar@bar.baz")))))\r
131 +\r
132 +(ert-deftest notmuch-fcc-regexp ()\r
133 +  "Allow a regexp in the `From' string."\r
134 +  (let ((fcc-config '(("foo@bar.baz" . "foosent")\r
135 +                     (".*" . "barsent"))))\r
136 +\r
137 +    (should (string= "foosent"\r
138 +                    (notmuch-fcc-determine-folder\r
139 +                     fcc-config "foo@bar.baz")))\r
140 +                    \r
141 +    (should (string= "barsent"\r
142 +                    (notmuch-fcc-determine-folder\r
143 +                     fcc-config "bar@bar.baz")))))\r
144 +\r
145 +(ert-deftest notmuch-fcc-oldstyle ()\r
146 +  "Raise an error for an old style configuration."\r
147 +\r
148 +  ;; No match.\r
149 +  (should-error (notmuch-fcc-determine-folder\r
150 +                '("sent" ("not@bar.baz" . "foosent"))\r
151 +                "foo@bar.baz"))\r
152 +  ;; One match.\r
153 +  (should-error (notmuch-fcc-determine-folder\r
154 +                '("sent" ("not@bar.baz" . "foosent"))\r
155 +                "not@bar.baz")))\r
156 +  \r
157 +\r
158 +;;\r
159 +\r
160 +(defun notmuch-test ()\r
161 +  "Run the notmuch ERT tests."\r
162 +  (interactive)\r
163 +\r
164 +  (ert t))\r
165 +\r
166 +(defun notmuch-test-batch ()\r
167 +  "Run the notmuch ERT tests in batch mode."\r
168 +  (ert-run-tests-batch-and-exit))\r
169 diff --git a/test/emacs-ert b/test/emacs-ert\r
170 new file mode 100755\r
171 index 0000000..4a45a66\r
172 --- /dev/null\r
173 +++ b/test/emacs-ert\r
174 @@ -0,0 +1,17 @@\r
175 +#!/bin/bash\r
176 +test_description="emacs interface (ert)"\r
177 +. test-lib.sh\r
178 +\r
179 +EXPECTED=../emacs.expected-output\r
180 +\r
181 +test_begin_subtest "Emacs tests using ert"\r
182 +output=$(emacs \\r
183 +    --batch --no-init-file --no-site-file \\r
184 +    --directory ../../emacs --directory ../ert \\r
185 +    --load notmuch-test.el \\r
186 +    --eval "(notmuch-test-batch)" \\r
187 +    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')\r
188 +expected=$(cat $EXPECTED/emacs-ert)\r
189 +test_expect_equal "$output" "$expected"\r
190 +\r
191 +test_done\r
192 diff --git a/test/emacs.expected-output/emacs-ert b/test/emacs.expected-output/emacs-ert\r
193 new file mode 100644\r
194 index 0000000..50f592b\r
195 --- /dev/null\r
196 +++ b/test/emacs.expected-output/emacs-ert\r
197 @@ -0,0 +1,9 @@\r
198 +Running 6 tests (today)\r
199 +   passed  1/6  notmuch-fcc-multiple\r
200 +   passed  2/6  notmuch-fcc-none\r
201 +   passed  3/6  notmuch-fcc-oldstyle\r
202 +   passed  4/6  notmuch-fcc-regexp\r
203 +   passed  5/6  notmuch-fcc-simple\r
204 +   passed  6/6  notmuch-fcc-trivial\r
205 +\r
206 +Ran 6 tests, 6 results as expected (today)\r
207 -- \r
208 1.7.2.3\r
209 \r