]> git.notmuchmail.org Git - notmuch/blob - test/emacs
test: set variables using `let' instead of `setq' in Emacs tests
[notmuch] / test / emacs
1 #!/usr/bin/env bash
2
3 # Note: do not use `setq' for setting variables in Emacs tests because
4 # it affects other tests that may run in the same Emacs instance.  Use
5 # `let' instead so the scope of the changed variables is limited to a
6 # single test.
7
8 test_description="emacs interface"
9 . test-lib.sh
10
11 EXPECTED=../emacs.expected-output
12
13 add_email_corpus
14
15 test_begin_subtest "Basic notmuch-hello view in emacs"
16 test_emacs '(notmuch-hello)
17             (test-output)'
18 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello
19
20 test_begin_subtest "Saved search with 0 results"
21 test_emacs '(let ((notmuch-show-empty-saved-searches t)
22                   (notmuch-saved-searches
23                    '\''(("inbox" . "tag:inbox")
24                         ("unread" . "tag:unread")
25                         ("empty" . "tag:doesnotexist"))))
26               (notmuch-hello)
27               (test-output))'
28 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty
29
30 test_begin_subtest "No saved searches displayed (all with 0 results)"
31 test_emacs '(let ((notmuch-saved-searches
32                    '\''(("empty" . "tag:doesnotexist"))))
33               (notmuch-hello)
34               (test-output))'
35 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches
36
37 test_begin_subtest "Basic notmuch-search view in emacs"
38 test_emacs '(notmuch-search "tag:inbox")
39             (notmuch-test-wait)
40             (test-output)'
41 test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox
42
43 test_begin_subtest "Navigation of notmuch-hello to search results"
44 test_emacs '(notmuch-hello)
45             (goto-char (point-min))
46             (re-search-forward "inbox")
47             (widget-button-press (point))
48             (notmuch-test-wait)
49             (test-output)'
50 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-view-inbox
51
52 test_begin_subtest "Basic notmuch-show view in emacs"
53 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
54 test_emacs "(notmuch-show \"$maildir_storage_thread\")
55             (test-output)"
56 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
57
58 test_begin_subtest "notmuch-show for message with invalid From"
59 add_message "[subject]=\"message-with-invalid-from\"" \
60             "[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""
61 thread=$(notmuch search --output=threads subject:message-with-invalid-from)
62 test_emacs "(notmuch-show \"$thread\")
63             (test-output)"
64 cat <<EOF >EXPECTED
65 "Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)
66 Subject: message-with-invalid-from
67 To: Notmuch Test Suite <test_suite@notmuchmail.org>
68 Date: Tue, 05 Jan 2001 15:43:57 -0000
69
70 This is just a test message (#1)
71 EOF
72 test_expect_equal_file OUTPUT EXPECTED
73
74 test_begin_subtest "Navigation of notmuch-search to thread view"
75 test_emacs '(notmuch-search "tag:inbox")
76             (notmuch-test-wait)
77             (goto-char (point-min))
78             (re-search-forward "Working with Maildir")
79             (notmuch-search-show-thread)
80             (notmuch-test-wait)
81             (test-output)'
82 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
83
84 test_begin_subtest "Add tag from search view"
85 os_x_darwin_thread=$(notmuch search --output=threads id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com)
86 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
87             (notmuch-test-wait)
88             (notmuch-search-add-tag \"tag-from-search-view\")"
89 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
90 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-search-view unread)"
91
92 test_begin_subtest "Remove tag from search view"
93 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
94             (notmuch-test-wait)
95             (notmuch-search-remove-tag \"tag-from-search-view\")"
96 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
97 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
98
99 test_begin_subtest "Add tag from notmuch-show view"
100 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
101             (notmuch-show-add-tag \"tag-from-show-view\")"
102 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
103 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-show-view unread)"
104
105 test_begin_subtest "Remove tag from notmuch-show view"
106 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
107             (notmuch-show-remove-tag \"tag-from-show-view\")"
108 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
109 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
110
111 test_begin_subtest "Message with .. in Message-Id:"
112 add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"'
113 test_emacs '(notmuch-search "id:\"123..456@example\"")
114             (notmuch-test-wait)
115             (notmuch-search-add-tag "search-add")
116             (notmuch-search-add-tag "search-remove")
117             (notmuch-search-remove-tag "search-remove")
118             (notmuch-show "id:\"123..456@example\"")
119             (notmuch-test-wait)
120             (notmuch-show-add-tag "show-add")
121             (notmuch-show-add-tag "show-remove")
122             (notmuch-show-remove-tag "show-remove")'
123 output=$(notmuch search 'id:"123..456@example"' | notmuch_search_sanitize)
124 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message with .. in Message-Id (inbox search-add show-add)"
125
126 test_begin_subtest "Sending a message via (fake) SMTP"
127 emacs_deliver_message \
128     'Testing message sent via SMTP' \
129     'This is a test that messages are sent via SMTP' \
130     '(message-goto-to)
131      (kill-whole-line)
132      (insert "To: user@example.com\n")'
133 sed \
134     -e s',^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' \
135     -e s',^Message-ID: <.*>$,Message-ID: <XXX>,' < sent_message >OUTPUT
136 cat <<EOF >EXPECTED
137 From: Notmuch Test Suite <test_suite@notmuchmail.org>
138 To: user@example.com
139 Subject: Testing message sent via SMTP
140 Date: 01 Jan 2000 12:00:00 -0000
141 User-Agent: Notmuch/XXX Emacs/XXX
142 Message-ID: <XXX>
143 MIME-Version: 1.0
144 Content-Type: text/plain; charset=us-ascii
145
146 This is a test that messages are sent via SMTP
147 EOF
148 test_expect_equal_file OUTPUT EXPECTED
149
150 test_begin_subtest "Verify that sent messages are saved/searchable (via FCC)"
151 notmuch new > /dev/null
152 output=$(notmuch search 'subject:"testing message sent via SMTP"' | notmuch_search_sanitize)
153 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; Testing message sent via SMTP (inbox)"
154
155 test_begin_subtest "notmuch-fcc-dirs set to nil"
156 test_emacs "(let ((notmuch-fcc-dirs nil))
157               (notmuch-mua-mail)
158               (test-output))"
159 cat <<EOF >EXPECTED
160 From: Notmuch Test Suite <test_suite@notmuchmail.org>
161 To: 
162 Subject: 
163 --text follows this line--
164 EOF
165 test_expect_equal_file OUTPUT EXPECTED
166
167 # Make another FCC maildir specific for the next test
168 mkdir -p mail/sent-string/cur
169 mkdir -p mail/sent-string/new
170 mkdir -p mail/sent-string/tmp
171
172 test_begin_subtest "notmuch-fcc-dirs set to a string"
173 test_emacs "(let ((notmuch-fcc-dirs \"sent-string\"))
174               (notmuch-mua-mail)
175               (test-output))"
176 cat <<EOF >EXPECTED
177 From: Notmuch Test Suite <test_suite@notmuchmail.org>
178 To: 
179 Subject: 
180 Fcc: ${MAIL_DIR}/sent-string
181 --text follows this line--
182 EOF
183 test_expect_equal_file OUTPUT EXPECTED
184
185 # Make more FCC maildirs specific for the next test
186 mkdir -p mail/sent-list-match/cur
187 mkdir -p mail/sent-list-match/new
188 mkdir -p mail/sent-list-match/tmp
189 mkdir -p mail/failure/cur
190 mkdir -p mail/failure/new
191 mkdir -p mail/failure/tmp
192
193 test_begin_subtest "notmuch-fcc-dirs set to a list (with match)"
194 test_emacs "(let ((notmuch-fcc-dirs
195                    '((\"notmuchmail.org\" . \"sent-list-match\")
196                      (\".*\" . \"failure\"))))
197               (notmuch-mua-mail)
198               (test-output))"
199 cat <<EOF >EXPECTED
200 From: Notmuch Test Suite <test_suite@notmuchmail.org>
201 To: 
202 Subject: 
203 Fcc: ${MAIL_DIR}/sent-list-match
204 --text follows this line--
205 EOF
206 test_expect_equal_file OUTPUT EXPECTED
207
208 # Make another FCC maildir specific for the next test
209 mkdir -p mail/sent-list-catch-all/cur
210 mkdir -p mail/sent-list-catch-all/new
211 mkdir -p mail/sent-list-catch-all/tmp
212  
213 test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)"
214 test_emacs "(let ((notmuch-fcc-dirs
215                    '((\"example.com\" . \"failure\")
216                      (\".*\" . \"sent-list-catch-all\"))))
217               (notmuch-mua-mail)
218               (test-output))"
219 cat <<EOF >EXPECTED
220 From: Notmuch Test Suite <test_suite@notmuchmail.org>
221 To: 
222 Subject: 
223 Fcc: ${MAIL_DIR}/sent-list-catch-all
224 --text follows this line--
225 EOF
226 test_expect_equal_file OUTPUT EXPECTED
227
228 test_begin_subtest "notmuch-fcc-dirs set to a list (no match)"
229 test_emacs "(let ((notmuch-fcc-dirs
230                    '((\"example.com\" . \"failure\")
231                      (\"nomatchhere.net\" . \"failure\"))))
232               (notmuch-mua-mail)
233               (test-output))"
234 cat <<EOF >EXPECTED
235 From: Notmuch Test Suite <test_suite@notmuchmail.org>
236 To: 
237 Subject: 
238 --text follows this line--
239 EOF
240 test_expect_equal_file OUTPUT EXPECTED
241
242 test_begin_subtest "Reply within emacs"
243 test_emacs '(notmuch-search "subject:\"testing message sent via SMTP\"")
244             (notmuch-test-wait)
245             (notmuch-search-reply-to-thread)
246             (test-output)'
247 sed -i -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' OUTPUT
248 cat <<EOF >EXPECTED
249 From: Notmuch Test Suite <test_suite@notmuchmail.org>
250 To: user@example.com
251 Subject: Re: Testing message sent via SMTP
252 In-Reply-To: <XXX>
253 Fcc: $(pwd)/mail/sent
254 --text follows this line--
255 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
256 > This is a test that messages are sent via SMTP
257 EOF
258 test_expect_equal_file OUTPUT EXPECTED
259
260 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
261 # save as archive to test that Emacs does not re-compress .gz
262 echo ./attachment1.gz |
263 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
264             (notmuch-show-save-attachments)' > /dev/null 2>&1
265 test_expect_equal_file attachment1.gz "$EXPECTED/attachment"
266
267 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"
268 # save as archive to test that Emacs does not re-compress .gz
269 echo ./attachment2.gz |
270 test_emacs '(notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5)' > /dev/null 2>&1
271 test_expect_equal_file attachment2.gz "$EXPECTED/attachment"
272
273 test_begin_subtest "View raw message within emacs"
274 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
275             (notmuch-show-view-raw-message)
276             (test-output)'
277 test_expect_equal_file OUTPUT $EXPECTED/raw-message-cf0c4d-52ad0a
278
279 test_begin_subtest "Hiding/showing signature in notmuch-show view"
280 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
281 test_emacs "(notmuch-show \"$maildir_storage_thread\")
282             (search-forward \"Click/Enter to show.\")
283             (button-activate (button-at (point)))
284             (search-backward \"Click/Enter to hide.\")
285             (button-activate (button-at (point)))
286             (test-output)"
287 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
288
289 test_begin_subtest "Detection and hiding of top-post quoting of message"
290 add_message '[subject]="The problem with top-posting"' \
291             [id]=top-post-target \
292             '[body]="A: Because it messes up the order in which people normally read text.
293 Q: Why is top-posting such a bad thing?
294 A: Top-posting.
295 Q: What is the most annoying thing in e-mail?"'
296 add_message '[from]="Top Poster <top@poster.com>"' \
297             [in-reply-to]=top-post-target \
298             [references]=top-post-target \
299             '[subject]="Re: The problem with top-posting"' \
300             '[body]="Thanks for the advice! I will be sure to put it to good use.
301
302 -Top Poster
303
304 ----- Original Message -----
305 From: Notmuch Test Suite <test_suite@notmuchmail.org>
306 To: Notmuch Test Suite <test_suite@notmuchmai.org>
307 Sent: Tue, 05 Jan 2001 15:43:57 -0000
308 Subject: The problem with top-posting
309
310 Q: Why is top-posting such a bad thing?
311 A: Top-posting.
312 Q: What is the most annoying thing in e-mail?"'
313 test_emacs "(notmuch-show \"top-posting\")
314             (test-visible-output)"
315 echo "Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
316 Subject: The problem with top-posting
317 To: Notmuch Test Suite <test_suite@notmuchmail.org>
318 Date: Tue, 05 Jan 2001 15:43:57 -0000
319
320 A: Because it messes up the order in which people normally read text.
321 Q: Why is top-posting such a bad thing?
322 A: Top-posting.
323 Q: What is the most annoying thing in e-mail?
324 Top Poster <top@poster.com> (2001-01-05) (inbox unread)
325 Subject: Re: The problem with top-posting
326 To: Notmuch Test Suite <test_suite@notmuchmail.org>
327 Date: Tue, 05 Jan 2001 15:43:57 -0000
328
329 Thanks for the advice! I will be sure to put it to good use.
330
331 -Top Poster
332
333 [ 9-line hidden original message. Click/Enter to show. ]" > EXPECTED
334 test_expect_equal_file OUTPUT EXPECTED
335
336 test_begin_subtest "Hiding message in notmuch-show view"
337 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
338             (notmuch-show-toggle-message)
339             (test-visible-output)'
340 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
341
342 test_begin_subtest "Hiding message with visible citation in notmuch-show view"
343 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
344             (search-forward "Click/Enter to show.")
345             (button-activate (button-at (point)))
346             (notmuch-show-toggle-message)
347             (test-visible-output)'
348 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
349
350 test_done