]> git.notmuchmail.org Git - notmuch/blob - test/emacs
emacs: test notmuch-indent-messages-width default
[notmuch] / test / emacs
1 #!/usr/bin/env bash
2
3 test_description="emacs interface"
4 . test-lib.sh
5
6 EXPECTED=$TEST_DIRECTORY/emacs.expected-output
7
8 add_email_corpus
9
10 test_begin_subtest "Basic notmuch-hello view in emacs"
11 test_emacs '(notmuch-hello)
12             (test-output)'
13 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello
14
15 test_begin_subtest "Saved search with 0 results"
16 test_emacs '(let ((notmuch-show-empty-saved-searches t)
17                   (notmuch-saved-searches
18                    '\''(("inbox" . "tag:inbox")
19                         ("unread" . "tag:unread")
20                         ("empty" . "tag:doesnotexist"))))
21               (notmuch-hello)
22               (test-output))'
23 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty
24
25 test_begin_subtest "No saved searches displayed (all with 0 results)"
26 test_emacs '(let ((notmuch-saved-searches
27                    '\''(("empty" . "tag:doesnotexist"))))
28               (notmuch-hello)
29               (test-output))'
30 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches
31
32 test_begin_subtest "Basic notmuch-search view in emacs"
33 test_emacs '(notmuch-search "tag:inbox")
34             (notmuch-test-wait)
35             (test-output)'
36 test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox
37
38 test_begin_subtest "Navigation of notmuch-hello to search results"
39 test_emacs '(notmuch-hello)
40             (goto-char (point-min))
41             (re-search-forward "inbox")
42             (widget-button-press (point))
43             (notmuch-test-wait)
44             (test-output)'
45 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-view-inbox
46
47 test_begin_subtest "Basic notmuch-show view in emacs"
48 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
49 test_emacs "(notmuch-show \"$maildir_storage_thread\")
50             (test-output)"
51 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
52
53 test_begin_subtest "Basic notmuch-show view in emacs default indentation"
54 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
55 test_emacs "(let ((notmuch-indent-messages-width 1))
56               (notmuch-show \"$maildir_storage_thread\")
57               (test-output))"
58 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
59
60 test_begin_subtest "notmuch-show for message with invalid From"
61 add_message "[subject]=\"message-with-invalid-from\"" \
62             "[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""
63 thread=$(notmuch search --output=threads subject:message-with-invalid-from)
64 test_emacs "(notmuch-show \"$thread\")
65             (test-output)"
66 cat <<EOF >EXPECTED
67 "Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)
68 Subject: message-with-invalid-from
69 To: Notmuch Test Suite <test_suite@notmuchmail.org>
70 Date: Tue, 05 Jan 2001 15:43:57 -0000
71
72 This is just a test message (#1)
73 EOF
74 test_expect_equal_file OUTPUT EXPECTED
75
76 test_begin_subtest "Navigation of notmuch-search to thread view"
77 test_emacs '(notmuch-search "tag:inbox")
78             (notmuch-test-wait)
79             (goto-char (point-min))
80             (re-search-forward "Working with Maildir")
81             (notmuch-search-show-thread)
82             (notmuch-test-wait)
83             (test-output)'
84 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
85
86 test_begin_subtest "Add tag from search view"
87 os_x_darwin_thread=$(notmuch search --output=threads id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com)
88 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
89             (notmuch-test-wait)
90             (notmuch-search-add-tag \"tag-from-search-view\")"
91 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
92 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)"
93
94 test_begin_subtest "Remove tag from search view"
95 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
96             (notmuch-test-wait)
97             (notmuch-search-remove-tag \"tag-from-search-view\")"
98 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
99 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)"
100
101 test_begin_subtest "Add tag from notmuch-show view"
102 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
103             (notmuch-show-add-tag \"tag-from-show-view\")"
104 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
105 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)"
106
107 test_begin_subtest "Remove tag from notmuch-show view"
108 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
109             (notmuch-show-remove-tag \"tag-from-show-view\")"
110 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
111 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)"
112
113 test_begin_subtest "Message with .. in Message-Id:"
114 add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"'
115 test_emacs '(notmuch-search "id:\"123..456@example\"")
116             (notmuch-test-wait)
117             (notmuch-search-add-tag "search-add")
118             (notmuch-search-add-tag "search-remove")
119             (notmuch-search-remove-tag "search-remove")
120             (notmuch-show "id:\"123..456@example\"")
121             (notmuch-test-wait)
122             (notmuch-show-add-tag "show-add")
123             (notmuch-show-add-tag "show-remove")
124             (notmuch-show-remove-tag "show-remove")'
125 output=$(notmuch search 'id:"123..456@example"' | notmuch_search_sanitize)
126 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message with .. in Message-Id (inbox search-add show-add)"
127
128 test_begin_subtest "Sending a message via (fake) SMTP"
129 emacs_deliver_message \
130     'Testing message sent via SMTP' \
131     'This is a test that messages are sent via SMTP' \
132     '(message-goto-to)
133      (kill-whole-line)
134      (insert "To: user@example.com\n")'
135 sed \
136     -e s',^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' \
137     -e s',^Message-ID: <.*>$,Message-ID: <XXX>,' < sent_message >OUTPUT
138 cat <<EOF >EXPECTED
139 From: Notmuch Test Suite <test_suite@notmuchmail.org>
140 To: user@example.com
141 Subject: Testing message sent via SMTP
142 Date: 01 Jan 2000 12:00:00 -0000
143 User-Agent: Notmuch/XXX Emacs/XXX
144 Message-ID: <XXX>
145 MIME-Version: 1.0
146 Content-Type: text/plain; charset=us-ascii
147
148 This is a test that messages are sent via SMTP
149 EOF
150 test_expect_equal_file OUTPUT EXPECTED
151
152 test_begin_subtest "Verify that sent messages are saved/searchable (via FCC)"
153 notmuch new > /dev/null
154 output=$(notmuch search 'subject:"testing message sent via SMTP"' | notmuch_search_sanitize)
155 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; Testing message sent via SMTP (inbox)"
156
157 test_begin_subtest "notmuch-fcc-dirs set to nil"
158 test_emacs "(let ((notmuch-fcc-dirs nil))
159               (notmuch-mua-mail)
160               (test-output))"
161 cat <<EOF >EXPECTED
162 From: Notmuch Test Suite <test_suite@notmuchmail.org>
163 To: 
164 Subject: 
165 --text follows this line--
166 EOF
167 test_expect_equal_file OUTPUT EXPECTED
168
169 # Make another FCC maildir specific for the next test
170 mkdir -p mail/sent-string/cur
171 mkdir -p mail/sent-string/new
172 mkdir -p mail/sent-string/tmp
173
174 test_begin_subtest "notmuch-fcc-dirs set to a string"
175 test_emacs "(let ((notmuch-fcc-dirs \"sent-string\"))
176               (notmuch-mua-mail)
177               (test-output))"
178 cat <<EOF >EXPECTED
179 From: Notmuch Test Suite <test_suite@notmuchmail.org>
180 To: 
181 Subject: 
182 Fcc: ${MAIL_DIR}/sent-string
183 --text follows this line--
184 EOF
185 test_expect_equal_file OUTPUT EXPECTED
186
187 # Make more FCC maildirs specific for the next test
188 mkdir -p mail/sent-list-match/cur
189 mkdir -p mail/sent-list-match/new
190 mkdir -p mail/sent-list-match/tmp
191 mkdir -p mail/failure/cur
192 mkdir -p mail/failure/new
193 mkdir -p mail/failure/tmp
194
195 test_begin_subtest "notmuch-fcc-dirs set to a list (with match)"
196 test_emacs "(let ((notmuch-fcc-dirs
197                    '((\"notmuchmail.org\" . \"sent-list-match\")
198                      (\".*\" . \"failure\"))))
199               (notmuch-mua-mail)
200               (test-output))"
201 cat <<EOF >EXPECTED
202 From: Notmuch Test Suite <test_suite@notmuchmail.org>
203 To: 
204 Subject: 
205 Fcc: ${MAIL_DIR}/sent-list-match
206 --text follows this line--
207 EOF
208 test_expect_equal_file OUTPUT EXPECTED
209
210 # Make another FCC maildir specific for the next test
211 mkdir -p mail/sent-list-catch-all/cur
212 mkdir -p mail/sent-list-catch-all/new
213 mkdir -p mail/sent-list-catch-all/tmp
214  
215 test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)"
216 test_emacs "(let ((notmuch-fcc-dirs
217                    '((\"example.com\" . \"failure\")
218                      (\".*\" . \"sent-list-catch-all\"))))
219               (notmuch-mua-mail)
220               (test-output))"
221 cat <<EOF >EXPECTED
222 From: Notmuch Test Suite <test_suite@notmuchmail.org>
223 To: 
224 Subject: 
225 Fcc: ${MAIL_DIR}/sent-list-catch-all
226 --text follows this line--
227 EOF
228 test_expect_equal_file OUTPUT EXPECTED
229
230 test_begin_subtest "notmuch-fcc-dirs set to a list (no match)"
231 test_emacs "(let ((notmuch-fcc-dirs
232                    '((\"example.com\" . \"failure\")
233                      (\"nomatchhere.net\" . \"failure\"))))
234               (notmuch-mua-mail)
235               (test-output))"
236 cat <<EOF >EXPECTED
237 From: Notmuch Test Suite <test_suite@notmuchmail.org>
238 To: 
239 Subject: 
240 --text follows this line--
241 EOF
242 test_expect_equal_file OUTPUT EXPECTED
243
244 test_begin_subtest "Reply within emacs"
245 test_emacs '(notmuch-search "subject:\"testing message sent via SMTP\"")
246             (notmuch-test-wait)
247             (notmuch-search-reply-to-thread)
248             (test-output)'
249 sed -i -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' OUTPUT
250 cat <<EOF >EXPECTED
251 From: Notmuch Test Suite <test_suite@notmuchmail.org>
252 To: user@example.com
253 Subject: Re: Testing message sent via SMTP
254 In-Reply-To: <XXX>
255 Fcc: $(pwd)/mail/sent
256 --text follows this line--
257 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
258 > This is a test that messages are sent via SMTP
259 EOF
260 test_expect_equal_file OUTPUT EXPECTED
261
262 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
263 # save as archive to test that Emacs does not re-compress .gz
264 test_emacs '(let ((standard-input "\"attachment1.gz\""))
265               (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
266               (notmuch-show-save-attachments))'
267 test_expect_equal_file attachment1.gz "$EXPECTED/attachment"
268
269 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"
270 # save as archive to test that Emacs does not re-compress .gz
271 test_emacs '(let ((standard-input "\"attachment2.gz\""))
272               (notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5))'
273 test_expect_equal_file attachment2.gz "$EXPECTED/attachment"
274
275 test_begin_subtest "View raw message within emacs"
276 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
277             (notmuch-show-view-raw-message)
278             (test-output)'
279 test_expect_equal_file OUTPUT $EXPECTED/raw-message-cf0c4d-52ad0a
280
281 test_begin_subtest "Hiding/showing signature in notmuch-show view"
282 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
283 test_emacs "(notmuch-show \"$maildir_storage_thread\")
284             (search-forward \"Click/Enter to show.\")
285             (button-activate (button-at (point)))
286             (search-backward \"Click/Enter to hide.\")
287             (button-activate (button-at (point)))
288             (test-output)"
289 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
290
291 test_begin_subtest "Detection and hiding of top-post quoting of message"
292 add_message '[subject]="The problem with top-posting"' \
293             [id]=top-post-target \
294             '[body]="A: Because it messes up the order in which people normally read text.
295 Q: Why is top-posting such a bad thing?
296 A: Top-posting.
297 Q: What is the most annoying thing in e-mail?"'
298 add_message '[from]="Top Poster <top@poster.com>"' \
299             [in-reply-to]=top-post-target \
300             [references]=top-post-target \
301             '[subject]="Re: The problem with top-posting"' \
302             '[body]="Thanks for the advice! I will be sure to put it to good use.
303
304 -Top Poster
305
306 ----- Original Message -----
307 From: Notmuch Test Suite <test_suite@notmuchmail.org>
308 To: Notmuch Test Suite <test_suite@notmuchmai.org>
309 Sent: Tue, 05 Jan 2001 15:43:57 -0000
310 Subject: The problem with top-posting
311
312 Q: Why is top-posting such a bad thing?
313 A: Top-posting.
314 Q: What is the most annoying thing in e-mail?"'
315 test_emacs "(notmuch-show \"top-posting\")
316             (test-visible-output)"
317 echo "Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
318 Subject: The problem with top-posting
319 To: Notmuch Test Suite <test_suite@notmuchmail.org>
320 Date: Tue, 05 Jan 2001 15:43:57 -0000
321
322 A: Because it messes up the order in which people normally read text.
323 Q: Why is top-posting such a bad thing?
324 A: Top-posting.
325 Q: What is the most annoying thing in e-mail?
326 Top Poster <top@poster.com> (2001-01-05) (inbox unread)
327 Subject: Re: The problem with top-posting
328 To: Notmuch Test Suite <test_suite@notmuchmail.org>
329 Date: Tue, 05 Jan 2001 15:43:57 -0000
330
331 Thanks for the advice! I will be sure to put it to good use.
332
333 -Top Poster
334
335 [ 9-line hidden original message. Click/Enter to show. ]" > EXPECTED
336 test_expect_equal_file OUTPUT EXPECTED
337
338 test_begin_subtest "Hiding message in notmuch-show view"
339 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
340             (notmuch-show-toggle-message)
341             (test-visible-output)'
342 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
343
344 test_begin_subtest "Hiding message with visible citation in notmuch-show view"
345 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
346             (search-forward "Click/Enter to show.")
347             (button-activate (button-at (point)))
348             (notmuch-show-toggle-message)
349             (test-visible-output)'
350 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
351
352 test_begin_subtest "Stashing in notmuch-show"
353 add_message '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
354     '[from]="Some One <someone@somewhere.org>"' \
355     '[to]="Some One Else <notsomeone@somewhere.org>"' \
356     '[cc]="Notmuch <notmuch@notmuchmail.org>"' \
357     '[subject]="Stash my stashables"' \
358     '[id]="bought"' \
359     '[body]="Unable to stash body. Where did you get it in the first place?!?"'
360 notmuch tag +stashtest id:${gen_msg_id}
361 test_emacs '(notmuch-show "id:\"bought\"")
362         (notmuch-show-stash-date)
363         (notmuch-show-stash-from)
364         (notmuch-show-stash-to)
365         (notmuch-show-stash-cc)
366         (notmuch-show-stash-subject)
367         (notmuch-show-stash-message-id)
368         (notmuch-show-stash-message-id-stripped)
369         (notmuch-show-stash-tags)
370         (notmuch-show-stash-filename)
371         (switch-to-buffer
372           (generate-new-buffer "*test-stashing*"))
373         (dotimes (i 9)
374           (yank)
375           (insert "\n")
376           (rotate-yank-pointer 1))
377         (reverse-region (point-min) (point-max))
378             (test-output)'
379 cat <<EOF >EXPECTED
380 Sat, 01 Jan 2000 12:00:00 -0000
381 Some One <someone@somewhere.org>
382 Some One Else <notsomeone@somewhere.org>
383 Notmuch <notmuch@notmuchmail.org>
384 Stash my stashables
385 id:"bought"
386 bought
387 inbox,stashtest
388 ${gen_msg_filename}
389 EOF
390 test_expect_equal_file OUTPUT EXPECTED
391
392 test_begin_subtest "Stashing in notmuch-search"
393 test_emacs '(notmuch-search "id:\"bought\"")
394         (notmuch-test-wait)
395         (notmuch-search-stash-thread-id)
396         (switch-to-buffer
397           (generate-new-buffer "*test-stashing*"))
398         (yank)
399             (test-output)'
400 sed -i -e 's/^thread:.*$/thread:XXX/' OUTPUT
401 test_expect_equal $(cat OUTPUT) "thread:XXX"
402
403 test_begin_subtest 'Hiding message following HTML part'
404 test_subtest_known_broken
405 id='html-message@notmuchmail.org'
406 emacs_deliver_message \
407     'HTML message' \
408     '' \
409     "(message-goto-eoh)
410      (insert \"Message-ID: <$id>\n\")
411      (message-goto-body)
412      (mml-insert-part \"text/html\")
413      (insert \"<body>This is a test HTML message</body>\")"
414 emacs_deliver_message \
415     'Reply to HTML message' \
416     'This is a reply to the test HTML message' \
417     "(message-goto-eoh)
418      (insert \"In-Reply-To: <$id>\n\")"
419 test_emacs "(notmuch-show \"id:$id\") \
420             (notmuch-show-next-message) \
421             (command-execute (key-binding (kbd \"RET\"))) \
422             (test-visible-output)"
423 test_emacs "(notmuch-show \"id:$id\") \
424             (notmuch-show-next-message) \
425             (notmuch-show-toggle-message) \
426             (test-visible-output \"EXPECTED\")"
427 test_expect_equal_file OUTPUT EXPECTED
428
429 test_begin_subtest 'notmuch-show-advance-and-archive with invisible signature'
430 message1='id:20091118010116.GC25380@dottiness.seas.harvard.edu'
431 message2='id:1258491078-29658-1-git-send-email-dottedmag@dottedmag.net'
432 test_emacs "(notmuch-search \"$message1 or $message2\")
433             (notmuch-test-wait)
434             (notmuch-search-show-thread)
435             (goto-char (point-max))
436             (redisplay)
437             (notmuch-show-advance-and-archive)
438             (test-output)"
439 test_emacs "(notmuch-show \"$message2\")
440             (test-output \"EXPECTED\")"
441 test_expect_equal_file OUTPUT EXPECTED
442
443 test_begin_subtest "Refresh show buffer"
444 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
445             (test-visible-output "EXPECTED")
446             (notmuch-show-refresh-view)
447             (test-visible-output)'
448 test_expect_equal_file OUTPUT EXPECTED
449
450 test_begin_subtest "Refresh modified show buffer"
451 test_subtest_known_broken
452 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
453             (notmuch-show-toggle-message)
454             (notmuch-show-next-message)
455             (notmuch-show-toggle-message)
456             (test-visible-output "EXPECTED")
457             (notmuch-show-refresh-view)
458             (test-visible-output)'
459 test_expect_equal_file OUTPUT EXPECTED
460
461 test_done