1 Return-Path: <dmitry.kurochkin@gmail.com>
\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 E1C07431FD0
\r
6 for <notmuch@notmuchmail.org>; Sun, 26 Jun 2011 16:53:32 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 32lCjoIr5B3j for <notmuch@notmuchmail.org>;
\r
17 Sun, 26 Jun 2011 16:53:29 -0700 (PDT)
\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 3CCB6429E38
\r
22 for <notmuch@notmuchmail.org>; Sun, 26 Jun 2011 16:53:25 -0700 (PDT)
\r
23 Received: by mail-bw0-f53.google.com with SMTP id 12so3882788bwg.26
\r
24 for <notmuch@notmuchmail.org>; Sun, 26 Jun 2011 16:53:24 -0700 (PDT)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
26 h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer
\r
27 :in-reply-to:references;
\r
28 bh=d6ZKnbav6AAAxxXf417lHvldZvMhFP37Hc32zzddQYY=;
\r
29 b=p9XwVX+MudFDeMYz99KBvv6ymdmapGWV2fuARhGlnTul4kC/jkvz80WjwRr/Yp/fPg
\r
30 1vVLSYQWoLRNNA5grAHxsH55FEXdxBHlniuY9yxtsGFKVdqXB9EPy7b2dQREmXqDI2h/
\r
31 EZL3Cpiq6f3IGubNcAqvsHS7Dymb+bWQRvqMM=
\r
32 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
\r
33 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
34 b=JHc/DN7fqs3bEu2GBeMjEEZZi+ryUd+Zz/IsFdRBgCDrmtHm7S5k8EsbQJLYzPgQNO
\r
35 cXrj9Xb1ZaxVJ2WXZeG5gvTjuyTT46x24aAygkCgA76U3Llo0XLa7BGhtfG/fgCA69Iw
\r
36 ep5xaZwF9Mk2rxjwUV4Xx65nNE8sNshQKgwzY=
\r
37 Received: by 10.204.83.33 with SMTP id d33mr3667225bkl.55.1309132404801;
\r
38 Sun, 26 Jun 2011 16:53:24 -0700 (PDT)
\r
39 Received: from localhost ([91.144.186.21])
\r
40 by mx.google.com with ESMTPS id c13sm176062bkc.2.2011.06.26.16.53.23
\r
41 (version=TLSv1/SSLv3 cipher=OTHER);
\r
42 Sun, 26 Jun 2011 16:53:23 -0700 (PDT)
\r
43 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH 4/5] test: save buffer content to file instead of printing it
\r
47 Date: Mon, 27 Jun 2011 03:52:58 +0400
\r
48 Message-Id: <1309132379-24089-4-git-send-email-dmitry.kurochkin@gmail.com>
\r
49 X-Mailer: git-send-email 1.7.5.4
\r
50 In-Reply-To: <1309132379-24089-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
51 References: <1309132379-24089-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
52 X-BeenThere: notmuch@notmuchmail.org
\r
53 X-Mailman-Version: 2.1.13
\r
55 List-Id: "Use and development of the notmuch mail system."
\r
56 <notmuch.notmuchmail.org>
\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
60 List-Post: <mailto:notmuch@notmuchmail.org>
\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
64 X-List-Received-Date: Sun, 26 Jun 2011 23:53:33 -0000
\r
66 Before the change, the common Emacs test scheme was to print
\r
67 buffer content to stdout and redirect it to a file or capture it
\r
68 in a shell variable. This does not work if we switch to using
\r
69 emacsclient(1) for running the tests, because you can not print
\r
70 to the stdout in this case. (Actually, you can print to stdout
\r
71 from Emacs server, but you can not capture the output on
\r
74 The patch introduces new Emacs test auxiliary functions:
\r
75 `test-output' and `test-visible-output'. These functions are
\r
76 used to save buffer content to a file directly from Emacs. For
\r
77 most tests the changes are trivial, because Emacs stdout output
\r
78 was redirected to a file anyway. But some tests captured the
\r
79 output in a shell variable and compare it with the expected
\r
80 output using test_expect_equal. These tests are changed to use
\r
81 files and test_expect_equal_file instead.
\r
83 Note: even if we do not switch Emacs tests to emacsclient(1), the
\r
84 patch makes tests cleaner and is an improvement.
\r
86 test/emacs | 71 ++++++++++++++++++++-------------------
\r
87 test/emacs-large-search-buffer | 23 +++++++++----
\r
88 test/test-lib.el | 10 ++++++
\r
89 3 files changed, 62 insertions(+), 42 deletions(-)
\r
91 diff --git a/test/emacs b/test/emacs
\r
92 index 1e46c0d..fc4c01f 100755
\r
95 @@ -8,7 +8,7 @@ add_email_corpus
\r
97 test_begin_subtest "Basic notmuch-hello view in emacs"
\r
98 test_emacs '(notmuch-hello)
\r
99 - (princ (buffer-string))' >OUTPUT
\r
101 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello
\r
103 test_begin_subtest "Saved search with 0 results"
\r
104 @@ -18,20 +18,20 @@ test_emacs '(setq notmuch-show-empty-saved-searches t)
\r
105 ("unread" . "tag:unread")
\r
106 ("empty" . "tag:doesnotexist")))
\r
108 - (princ (buffer-string))' >OUTPUT
\r
110 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty
\r
112 test_begin_subtest "No saved searches displayed (all with 0 results)"
\r
113 test_emacs '(setq notmuch-saved-searches
\r
114 '\''(("empty" . "tag:doesnotexist")))
\r
116 - (princ (buffer-string))' >OUTPUT
\r
118 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches
\r
120 test_begin_subtest "Basic notmuch-search view in emacs"
\r
121 test_emacs '(notmuch-search "tag:inbox")
\r
122 (notmuch-test-wait)
\r
123 - (princ (buffer-string))' >OUTPUT
\r
125 test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox
\r
127 test_begin_subtest "Navigation of notmuch-hello to search results"
\r
128 @@ -40,27 +40,30 @@ test_emacs '(notmuch-hello)
\r
129 (re-search-forward "inbox")
\r
130 (widget-button-press (point))
\r
131 (notmuch-test-wait)
\r
132 - (princ (buffer-string))' >OUTPUT
\r
134 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-view-inbox
\r
136 test_begin_subtest "Basic notmuch-show view in emacs"
\r
137 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
\r
138 test_emacs "(notmuch-show \"$maildir_storage_thread\")
\r
139 - (princ (buffer-string))" >OUTPUT
\r
141 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
\r
143 test_begin_subtest "notmuch-show for message with invalid From"
\r
144 add_message "[subject]=\"message-with-invalid-from\"" \
\r
145 "[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""
\r
146 thread=$(notmuch search --output=threads subject:message-with-invalid-from)
\r
147 -output=$(test_emacs "(notmuch-show \"$thread\") (princ (buffer-string))")
\r
148 -test_expect_equal "$output" \
\r
149 -'"Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)
\r
150 +test_emacs "(notmuch-show \"$thread\")
\r
152 +cat <<EOF >EXPECTED
\r
153 +"Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)
\r
154 Subject: message-with-invalid-from
\r
155 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
156 Date: Tue, 05 Jan 2001 15:43:57 -0000
\r
158 -This is just a test message (#1)'
\r
159 +This is just a test message (#1)
\r
161 +test_expect_equal_file OUTPUT EXPECTED
\r
163 test_begin_subtest "Navigation of notmuch-search to thread view"
\r
164 test_emacs '(notmuch-search "tag:inbox")
\r
165 @@ -69,7 +72,7 @@ test_emacs '(notmuch-search "tag:inbox")
\r
166 (re-search-forward "Working with Maildir")
\r
167 (notmuch-search-show-thread)
\r
168 (notmuch-test-wait)
\r
169 - (princ (buffer-string))' >OUTPUT
\r
171 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
\r
173 test_begin_subtest "Add tag from search view"
\r
174 @@ -162,7 +165,7 @@ test_expect_equal "$output" "thread:XXX 1974-03-29 [1/1] Notmuch Test Suite; T
\r
175 test_begin_subtest "notmuch-fcc-dirs set to nil"
\r
176 test_emacs "(setq notmuch-fcc-dirs nil)
\r
178 - (princ (buffer-string))" > OUTPUT
\r
180 cat <<EOF >EXPECTED
\r
181 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
183 @@ -179,7 +182,7 @@ mkdir -p mail/sent-string/tmp
\r
184 test_begin_subtest "notmuch-fcc-dirs set to a string"
\r
185 test_emacs "(setq notmuch-fcc-dirs \"sent-string\")
\r
187 - (princ (buffer-string))" > OUTPUT
\r
189 cat <<EOF >EXPECTED
\r
190 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
192 @@ -202,7 +205,7 @@ test_emacs "(setq notmuch-fcc-dirs
\r
193 '((\"notmuchmail.org\" . \"sent-list-match\")
\r
194 (\".*\" . \"failure\")))
\r
196 - (princ (buffer-string))" > OUTPUT
\r
198 cat <<EOF >EXPECTED
\r
199 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
201 @@ -222,7 +225,7 @@ test_emacs "(setq notmuch-fcc-dirs
\r
202 '((\"example.com\" . \"failure\")
\r
203 (\".*\" . \"sent-list-catch-all\")))
\r
205 - (princ (buffer-string))" > OUTPUT
\r
207 cat <<EOF >EXPECTED
\r
208 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
210 @@ -237,7 +240,7 @@ test_emacs "(setq notmuch-fcc-dirs
\r
211 '((\"example.com\" . \"failure\")
\r
212 (\"nomatchhere.net\" . \"failure\")))
\r
214 - (princ (buffer-string))" > OUTPUT
\r
216 cat <<EOF >EXPECTED
\r
217 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
219 @@ -252,9 +255,9 @@ test_begin_subtest "Reply within emacs"
\r
220 test_emacs '(notmuch-search "subject:\"testing message sent via SMTP\"")
\r
221 (notmuch-test-wait)
\r
222 (notmuch-search-reply-to-thread)
\r
223 - (princ (buffer-string))' |
\r
224 -sed -ne '/^From/,$ p' |
\r
225 -sed -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' >OUTPUT
\r
227 +sed -i -ne '/^From/,$ p' OUTPUT
\r
228 +sed -i -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' OUTPUT
\r
229 cat <<EOF >EXPECTED
\r
230 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
231 To: user@example.com
\r
232 @@ -284,8 +287,8 @@ test_begin_subtest "View raw message within emacs"
\r
233 first_line=$(head -n1 $EXPECTED/raw-message-cf0c4d-52ad0a)
\r
234 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
\r
235 (notmuch-show-view-raw-message)
\r
236 - (princ (buffer-string))' |
\r
237 -sed -ne "/$first_line/,\$ p" >OUTPUT
\r
239 +sed -i -ne "/$first_line/,\$ p" OUTPUT
\r
240 test_expect_equal_file OUTPUT $EXPECTED/raw-message-cf0c4d-52ad0a
\r
242 test_begin_subtest "Hiding/showing signature in notmuch-show view"
\r
243 @@ -295,7 +298,7 @@ test_emacs "(notmuch-show \"$maildir_storage_thread\")
\r
244 (button-activate (button-at (point)))
\r
245 (search-backward \"Click/Enter to hide.\")
\r
246 (button-activate (button-at (point)))
\r
247 - (princ (buffer-string))" >OUTPUT
\r
249 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
\r
251 test_begin_subtest "Detection and hiding of top-post quoting of message"
\r
252 @@ -323,7 +326,7 @@ Q: Why is top-posting such a bad thing?
\r
254 Q: What is the most annoying thing in e-mail?"'
\r
255 test_emacs "(notmuch-show \"top-posting\")
\r
256 - (princ (visible-buffer-string))" >OUTPUT
\r
257 + (test-visible-output)"
\r
258 echo "Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
\r
259 Subject: The problem with top-posting
\r
260 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
261 @@ -346,19 +349,17 @@ Thanks for the advice! I will be sure to put it to good use.
\r
262 test_expect_equal_file OUTPUT EXPECTED
\r
264 test_begin_subtest "Hiding message in notmuch-show view"
\r
265 -output=$(test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
\r
266 - (notmuch-show-toggle-message)
\r
267 - (princ (visible-buffer-string))')
\r
268 -expected=$(cat $EXPECTED/notmuch-show-thread-with-hidden-messages)
\r
269 -test_expect_equal "$output" "$expected"
\r
270 +test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
\r
271 + (notmuch-show-toggle-message)
\r
272 + (test-visible-output)'
\r
273 +test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
\r
275 test_begin_subtest "Hiding message with visible citation in notmuch-show view"
\r
276 -output=$(test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
\r
277 - (search-forward "Click/Enter to show.")
\r
278 - (button-activate (button-at (point)))
\r
279 - (notmuch-show-toggle-message)
\r
280 - (princ (visible-buffer-string))')
\r
281 -expected=$(cat $EXPECTED/notmuch-show-thread-with-hidden-messages)
\r
282 -test_expect_equal "$output" "$expected"
\r
283 +test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
\r
284 + (search-forward "Click/Enter to show.")
\r
285 + (button-activate (button-at (point)))
\r
286 + (notmuch-show-toggle-message)
\r
287 + (test-visible-output)'
\r
288 +test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
\r
291 diff --git a/test/emacs-large-search-buffer b/test/emacs-large-search-buffer
\r
292 index c78ce33..6095e9d 100755
\r
293 --- a/test/emacs-large-search-buffer
\r
294 +++ b/test/emacs-large-search-buffer
\r
295 @@ -19,16 +19,25 @@ done
\r
296 notmuch new > /dev/null
\r
298 test_begin_subtest "Ensure that emacs doesn't drop results"
\r
299 -expected="$(notmuch search '*' | sed -e 's/^thread:[0-9a-f]* //' -e 's/;//' -e 's/xx*/[BLOB]/')
\r
300 -End of search results."
\r
301 +notmuch search '*' > EXPEXTED
\r
302 +sed -i -e 's/^thread:[0-9a-f]* //' -e 's/;//' -e 's/xx*/[BLOB]/' EXPEXTED
\r
303 +echo 'End of search results.' >> EXPEXTED
\r
305 -output=$(test_emacs '(notmuch-search "*") (notmuch-test-wait) (princ (buffer-string))' | sed -e s', *, ,g' -e 's/xxx*/[BLOB]/g')
\r
306 -test_expect_equal "$output" "$expected"
\r
307 +test_emacs '(notmuch-search "*")
\r
308 + (notmuch-test-wait)
\r
310 +sed -i -e s', *, ,g' -e 's/xxx*/[BLOB]/g' OUTPUT
\r
311 +test_expect_equal_file OUTPUT EXPEXTED
\r
313 test_begin_subtest "Ensure that emacs doesn't drop error messages"
\r
314 -output=$(test_emacs '(notmuch-search "--this-option-does-not-exist") (notmuch-test-wait) (princ (buffer-string))')
\r
315 -test_expect_equal "$output" "Error: Unexpected output from notmuch search:
\r
316 +test_emacs '(notmuch-search "--this-option-does-not-exist")
\r
317 + (notmuch-test-wait)
\r
319 +cat <<EOF >EXPEXTED
\r
320 +Error: Unexpected output from notmuch search:
\r
321 Unrecognized option: --this-option-does-not-exist
\r
322 -End of search results. (process returned 1)"
\r
323 +End of search results. (process returned 1)
\r
325 +test_expect_equal_file OUTPUT EXPEXTED
\r
328 diff --git a/test/test-lib.el b/test/test-lib.el
\r
329 index 344a02e..4e7f5cf 100644
\r
330 --- a/test/test-lib.el
\r
331 +++ b/test/test-lib.el
\r
333 (while (get-buffer-process (current-buffer))
\r
336 +(defun test-output (&optional filename)
\r
337 + "Save current buffer to file FILENAME. Default FILENAME is OUTPUT."
\r
338 + (write-region (point-min) (point-max) (or filename "OUTPUT")))
\r
340 +(defun test-visible-output (&optional filename)
\r
341 + "Save visible text in current buffer to file FILENAME. Default
\r
342 +FILENAME is OUTPUT."
\r
343 + (let ((text (visible-buffer-string)))
\r
344 + (with-temp-file (or filename "OUTPUT") (insert text))))
\r
346 (defun visible-buffer-string ()
\r
347 "Same as `buffer-string', but excludes invisible text."
\r
348 (visible-buffer-substring (point-min) (point-max)))
\r