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