Re: notmuch and "mute" -- useful to anyone?
[notmuch-archives.git] / 07 / 679c2debfd2e606eb5052a3d7488179872b818
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 03965429E4D\r
6         for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:56:27 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \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 LJUPwXYPpuTh for <notmuch@notmuchmail.org>;\r
17         Mon, 27 Jun 2011 21:56:26 -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 9D069429E4A\r
22         for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:56:25 -0700 (PDT)\r
23 Received: by bwg12 with SMTP id 12so4894899bwg.26\r
24         for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:56: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=0fYxnIsYosbhVrdaNl28aBtNW187TYjiveyeKCohL/k=;\r
29         b=sWV61pwdd5hPn4rp9GBpsnQ1F5b1gxBQMJAlaGWS3nKfReYQvQstmmvdNCbRmfRK98\r
30         9c38gClUTCj8XeL1jWG/YPVhCP4ndvK0wp259xBpzwQwRzxGV2cPEg1M/iphqZuinLbB\r
31         gUqM50jxP2WQO4gNsp21aCzHgIeJcOMKYr4O8=\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=VeeeU9SQlW6hmWwiPhPlTvVQN7/QQvaiWDcqpBCylZHvQMpS7Qlim0WHoshMsoupO1\r
35         78bCPLsg5ZF4cZGaCK+Wmir0K6kBK5UwrTJkP2G5VYquoTPDck8r1E8qOifBsa8T1sO7\r
36         FQ/g3bwJi2sjsbgCjigXo+VEsRgESsl5WpQws=\r
37 Received: by 10.204.77.194 with SMTP id h2mr1105966bkk.144.1309236984108;\r
38         Mon, 27 Jun 2011 21:56:24 -0700 (PDT)\r
39 Received: from localhost ([91.144.186.21])\r
40         by mx.google.com with ESMTPS id e6sm51830bka.23.2011.06.27.21.56.22\r
41         (version=TLSv1/SSLv3 cipher=OTHER);\r
42         Mon, 27 Jun 2011 21:56:23 -0700 (PDT)\r
43 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
44 To: notmuch@notmuchmail.org\r
45 Subject: [PATCH] test: use emacsclient(1) for Emacs tests\r
46 Date: Tue, 28 Jun 2011 08:56:17 +0400\r
47 Message-Id: <1309236977-7974-1-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-10-git-send-email-dmitry.kurochkin@gmail.com>\r
50 References: <1309236311-2162-10-git-send-email-dmitry.kurochkin@gmail.com>\r
51 X-BeenThere: notmuch@notmuchmail.org\r
52 X-Mailman-Version: 2.1.13\r
53 Precedence: list\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:56:27 -0000\r
64 \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
74 \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
79 ---\r
80 \r
81 Amended patch with a more appropriate Emacs server name.  Sorry,\r
82 for inconvenience, should go to sleep.\r
83 \r
84 Regards,\r
85   Dmitry\r
86 \r
87  test/emacs       |   10 +++++-----\r
88  test/test-lib.el |   13 +++++++++++++\r
89  test/test-lib.sh |   24 +++++++++++++-----------\r
90  3 files changed, 31 insertions(+), 16 deletions(-)\r
91 \r
92 diff --git a/test/emacs b/test/emacs\r
93 index 3d42645..0f5f99c 100755\r
94 --- a/test/emacs\r
95 +++ b/test/emacs\r
96 @@ -259,15 +259,15 @@ test_expect_equal_file OUTPUT EXPECTED\r
97  \r
98  test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"\r
99  # save as archive to test that Emacs does not re-compress .gz\r
100 -echo ./attachment1.gz |\r
101 -test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")\r
102 -           (notmuch-show-save-attachments)' > /dev/null 2>&1\r
103 +test_emacs '(let ((standard-input "\"attachment1.gz\""))\r
104 +             (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")\r
105 +             (notmuch-show-save-attachments))' > /dev/null 2>&1\r
106  test_expect_equal_file attachment1.gz "$EXPECTED/attachment"\r
107  \r
108  test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"\r
109  # save as archive to test that Emacs does not re-compress .gz\r
110 -echo ./attachment2.gz |\r
111 -test_emacs '(notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5)' > /dev/null 2>&1\r
112 +test_emacs '(let ((standard-input "\"attachment2.gz\""))\r
113 +             (notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5))' > /dev/null 2>&1\r
114  test_expect_equal_file attachment2.gz "$EXPECTED/attachment"\r
115  \r
116  test_begin_subtest "View raw message within emacs"\r
117 diff --git a/test/test-lib.el b/test/test-lib.el\r
118 index 4e7f5cf..a783936 100644\r
119 --- a/test/test-lib.el\r
120 +++ b/test/test-lib.el\r
121 @@ -23,6 +23,12 @@\r
122  ;; avoid crazy 10-column default of --batch\r
123  (set-frame-width (window-frame (get-buffer-window)) 80)\r
124  \r
125 +;; `read-file-name' by default uses `completing-read' function to read\r
126 +;; user input.  It does not respect `standard-input' variable which we\r
127 +;; use in tests to provide user input.  So replace it with a plain\r
128 +;; `read' call.\r
129 +(setq read-file-name-function (lambda (&rest _) (read)))\r
130 +\r
131  (defun notmuch-test-wait ()\r
132    "Wait for process completion."\r
133    (while (get-buffer-process (current-buffer))\r
134 @@ -51,3 +57,10 @@ FILENAME is OUTPUT."\r
135           (setq str (concat str (buffer-substring start next-pos))))\r
136         (setq start next-pos)))\r
137      str))\r
138 +\r
139 +(defun orphan-watchdog (pid)\r
140 +  "Periodically check that the process with id PID is still\r
141 +running, quit if it terminated."\r
142 +  (if (not (process-attributes pid))\r
143 +      (kill-emacs)\r
144 +    (run-at-time "1 min" nil 'orphan-watchdog pid)))\r
145 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
146 index 48bace2..bcf18ec 100755\r
147 --- a/test/test-lib.sh\r
148 +++ b/test/test-lib.sh\r
149 @@ -829,6 +829,8 @@ test_done () {\r
150  \r
151         echo\r
152  \r
153 +       [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'\r
154 +\r
155         if [ "$test_failure" = "0" ]; then\r
156             if [ "$test_broken" = "0" ]; then       \r
157                 rm -rf "$remove_tmp"\r
158 @@ -848,16 +850,8 @@ emacs_generate_script () {\r
159  export PATH=$PATH\r
160  export NOTMUCH_CONFIG=$NOTMUCH_CONFIG\r
161  \r
162 -# We assume that the user will give a command-line argument only if\r
163 -# wanting to run in batch mode.\r
164 -if [ \$# -gt 0 ]; then\r
165 -       BATCH=--batch\r
166 -fi\r
167 -\r
168  # Here's what we are using here:\r
169  #\r
170 -# --batch:             Quit after given commands and print all (messages)\r
171 -#\r
172  # --no-init-file       Don't load users ~/.emacs\r
173  #\r
174  # --no-site-file       Don't load the site-wide startup stuff\r
175 @@ -866,16 +860,24 @@ fi\r
176  #\r
177  # --load               Force loading of notmuch.el and test-lib.el\r
178  \r
179 -emacs \$BATCH --no-init-file --no-site-file \\r
180 +emacs --no-init-file --no-site-file \\r
181         --directory "$TMP_DIRECTORY/../../emacs" --load notmuch.el \\r
182         --directory "$TMP_DIRECTORY/.." --load test-lib.el \\r
183 -       --eval "(progn \$@)"\r
184 +       "\$@"\r
185  EOF\r
186         chmod a+x "$TMP_DIRECTORY/run_emacs"\r
187  }\r
188  \r
189  test_emacs () {\r
190 -       "$TMP_DIRECTORY/run_emacs" "$@"\r
191 +       if [ -z "$EMACS_SERVER" ]; then\r
192 +               EMACS_SERVER="notmuch-test-suite-$$"\r
193 +               "$TMP_DIRECTORY/run_emacs" \\r
194 +                       --daemon \\r
195 +                       --eval "(setq server-name \"$EMACS_SERVER\")" \\r
196 +                       --eval "(orphan-watchdog $$)" || return\r
197 +       fi\r
198 +\r
199 +       emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"\r
200  }\r
201  \r
202  \r
203 -- \r
204 1.7.5.4\r
205 \r