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 59724421175
\r
6 for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:45:55 -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 AK08Hwze01Xs for <notmuch@notmuchmail.org>;
\r
17 Mon, 27 Jun 2011 21:45:53 -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 CCFBC429E59
\r
22 for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:45:50 -0700 (PDT)
\r
23 Received: by mail-bw0-f53.google.com with SMTP id 12so4889638bwg.26
\r
24 for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:45:50 -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=4CzoeJ84PeL+RzqWxiAO1o9+PivJZuy6ndSPq1ABK5c=;
\r
29 b=LCmLMtjuGaeMLAV9ycLdQYJQwe6rCcUSd5GFbAvHEP7mQDy+RXsJbkmJlq0GqZNm/B
\r
30 AWgC5MGvRdpQ8ysL6i3ZLE2CuDvGBvoPfE97qxIXg86lyvRBKrEEhpWtATKv8OG6+N5H
\r
31 a+3C/QTWlg84dKhIOqxjJACSCBoCChsGb718g=
\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=UWAJMJARZ4GKob9/Q8vg+0YWjp84D3ohDutlub+XGxsU/2fVhT/22wYdUqq3MkgWie
\r
35 zLJeHAGwgwVHjrMHSYobuRJ0oSPZPAxyd9P/PQxusG+5VkOYd0tDAmfE5zrW49qmrHxo
\r
36 fdcJqCLPwzQFI/G5rhfRIpJ9dAEIPisYQ2bVY=
\r
37 Received: by 10.204.136.1 with SMTP id p1mr5207274bkt.105.1309236350509;
\r
38 Mon, 27 Jun 2011 21:45:50 -0700 (PDT)
\r
39 Received: from localhost ([91.144.186.21])
\r
40 by mx.google.com with ESMTPS id ek1sm4746053bkb.9.2011.06.27.21.45.49
\r
41 (version=TLSv1/SSLv3 cipher=OTHER);
\r
42 Mon, 27 Jun 2011 21:45:49 -0700 (PDT)
\r
43 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH 10/10] test: use emacsclient(1) for Emacs tests
\r
46 Date: Tue, 28 Jun 2011 08:45:11 +0400
\r
47 Message-Id: <1309236311-2162-10-git-send-email-dmitry.kurochkin@gmail.com>
\r
48 X-Mailer: git-send-email 1.7.5.4
\r
49 In-Reply-To: <1309236311-2162-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
50 References: <1309236311-2162-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
51 X-BeenThere: notmuch@notmuchmail.org
\r
52 X-Mailman-Version: 2.1.13
\r
54 List-Id: "Use and development of the notmuch mail system."
\r
55 <notmuch.notmuchmail.org>
\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
59 List-Post: <mailto:notmuch@notmuchmail.org>
\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
63 X-List-Received-Date: Tue, 28 Jun 2011 04:45:55 -0000
\r
65 Before the change, every Emacs test ran in a separate Emacs
\r
66 instance. Starting Emacs many times wastes considerable time and
\r
67 it gets worse as the test suite grows. The patch solves this by
\r
68 using a single Emacs server and emacsclient(1) to run multiple
\r
69 tests. Emacs server is started on the first test_emacs call and
\r
70 stopped when test_done is called. We take care not to leave
\r
71 orphan Emacs processes behind when test is terminated by whatever
\r
72 reason: Emacs server runs a watchdog that periodically checks
\r
73 that the test is still running.
\r
75 Some tests need to provide user input. Before the change, this
\r
76 was done using echo(1) to Emacs stdin. This no longer works and
\r
77 instead `standard-input' variable is set accordingly to make
\r
78 `read' return the appropriate string.
\r
80 test/emacs | 10 +++++-----
\r
81 test/test-lib.el | 13 +++++++++++++
\r
82 test/test-lib.sh | 24 +++++++++++++-----------
\r
83 3 files changed, 31 insertions(+), 16 deletions(-)
\r
85 diff --git a/test/emacs b/test/emacs
\r
86 index 3d42645..0f5f99c 100755
\r
89 @@ -259,15 +259,15 @@ test_expect_equal_file OUTPUT EXPECTED
\r
91 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
\r
92 # save as archive to test that Emacs does not re-compress .gz
\r
93 -echo ./attachment1.gz |
\r
94 -test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
\r
95 - (notmuch-show-save-attachments)' > /dev/null 2>&1
\r
96 +test_emacs '(let ((standard-input "\"attachment1.gz\""))
\r
97 + (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
\r
98 + (notmuch-show-save-attachments))' > /dev/null 2>&1
\r
99 test_expect_equal_file attachment1.gz "$EXPECTED/attachment"
\r
101 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"
\r
102 # save as archive to test that Emacs does not re-compress .gz
\r
103 -echo ./attachment2.gz |
\r
104 -test_emacs '(notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5)' > /dev/null 2>&1
\r
105 +test_emacs '(let ((standard-input "\"attachment2.gz\""))
\r
106 + (notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5))' > /dev/null 2>&1
\r
107 test_expect_equal_file attachment2.gz "$EXPECTED/attachment"
\r
109 test_begin_subtest "View raw message within emacs"
\r
110 diff --git a/test/test-lib.el b/test/test-lib.el
\r
111 index 4e7f5cf..a783936 100644
\r
112 --- a/test/test-lib.el
\r
113 +++ b/test/test-lib.el
\r
115 ;; avoid crazy 10-column default of --batch
\r
116 (set-frame-width (window-frame (get-buffer-window)) 80)
\r
118 +;; `read-file-name' by default uses `completing-read' function to read
\r
119 +;; user input. It does not respect `standard-input' variable which we
\r
120 +;; use in tests to provide user input. So replace it with a plain
\r
122 +(setq read-file-name-function (lambda (&rest _) (read)))
\r
124 (defun notmuch-test-wait ()
\r
125 "Wait for process completion."
\r
126 (while (get-buffer-process (current-buffer))
\r
127 @@ -51,3 +57,10 @@ FILENAME is OUTPUT."
\r
128 (setq str (concat str (buffer-substring start next-pos))))
\r
129 (setq start next-pos)))
\r
132 +(defun orphan-watchdog (pid)
\r
133 + "Periodically check that the process with id PID is still
\r
134 +running, quit if it terminated."
\r
135 + (if (not (process-attributes pid))
\r
137 + (run-at-time "1 min" nil 'orphan-watchdog pid)))
\r
138 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
139 index 48bace2..e8f8629 100755
\r
140 --- a/test/test-lib.sh
\r
141 +++ b/test/test-lib.sh
\r
142 @@ -829,6 +829,8 @@ test_done () {
\r
146 + [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
\r
148 if [ "$test_failure" = "0" ]; then
\r
149 if [ "$test_broken" = "0" ]; then
\r
150 rm -rf "$remove_tmp"
\r
151 @@ -848,16 +850,8 @@ emacs_generate_script () {
\r
153 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
\r
155 -# We assume that the user will give a command-line argument only if
\r
156 -# wanting to run in batch mode.
\r
157 -if [ \$# -gt 0 ]; then
\r
161 # Here's what we are using here:
\r
163 -# --batch: Quit after given commands and print all (messages)
\r
165 # --no-init-file Don't load users ~/.emacs
\r
167 # --no-site-file Don't load the site-wide startup stuff
\r
168 @@ -866,16 +860,24 @@ fi
\r
170 # --load Force loading of notmuch.el and test-lib.el
\r
172 -emacs \$BATCH --no-init-file --no-site-file \
\r
173 +emacs --no-init-file --no-site-file \
\r
174 --directory "$TMP_DIRECTORY/../../emacs" --load notmuch.el \
\r
175 --directory "$TMP_DIRECTORY/.." --load test-lib.el \
\r
176 - --eval "(progn \$@)"
\r
179 chmod a+x "$TMP_DIRECTORY/run_emacs"
\r
183 - "$TMP_DIRECTORY/run_emacs" "$@"
\r
184 + if [ -z "$EMACS_SERVER" ]; then
\r
185 + EMACS_SERVER="notmuch-server-$$"
\r
186 + "$TMP_DIRECTORY/run_emacs" \
\r
188 + --eval "(setq server-name \"$EMACS_SERVER\")" \
\r
189 + --eval "(orphan-watchdog $$)" || return
\r
192 + emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
\r