Re: Hi all
[notmuch-archives.git] / c7 / f63ee296bf6109b6a62b194f5e3569b52b3b28
1 Return-Path: <jani@nikula.org>\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 839D2429E31\r
6         for <notmuch@notmuchmail.org>; Thu,  8 Dec 2011 14:48:49 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[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 C9MVd3t3C19l for <notmuch@notmuchmail.org>;\r
17         Thu,  8 Dec 2011 14:48:47 -0800 (PST)\r
18 Received: from mail-ey0-f181.google.com (mail-ey0-f181.google.com\r
19         [209.85.215.181]) (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 5B882429E2E\r
22         for <notmuch@notmuchmail.org>; Thu,  8 Dec 2011 14:48:47 -0800 (PST)\r
23 Received: by mail-ey0-f181.google.com with SMTP id l13so1711208eaa.26\r
24         for <notmuch@notmuchmail.org>; Thu, 08 Dec 2011 14:48:47 -0800 (PST)\r
25 Received: by 10.213.22.197 with SMTP id o5mr1312547ebb.55.1323384527075;\r
26         Thu, 08 Dec 2011 14:48:47 -0800 (PST)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id 58sm23179839eet.11.2011.12.08.14.48.45\r
30         (version=SSLv3 cipher=OTHER); Thu, 08 Dec 2011 14:48:46 -0800 (PST)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH v4 3/3] test: add tests for hooks\r
34 Date: Fri,  9 Dec 2011 00:48:31 +0200\r
35 Message-Id:\r
36  <8cd10b58761ace1834368427182925c1c32e9f1b.1323384304.git.jani@nikula.org>\r
37 X-Mailer: git-send-email 1.7.5.4\r
38 In-Reply-To: <cover.1323384304.git.jani@nikula.org>\r
39 References:\r
40  <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>\r
41         <cover.1323384304.git.jani@nikula.org>\r
42 In-Reply-To: <cover.1323384304.git.jani@nikula.org>\r
43 References: <cover.1323384304.git.jani@nikula.org>\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Thu, 08 Dec 2011 22:48:49 -0000\r
57 \r
58 Signed-off-by: Jani Nikula <jani@nikula.org>\r
59 ---\r
60  test/hooks        |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
61  test/notmuch-test |    1 +\r
62  2 files changed, 105 insertions(+), 0 deletions(-)\r
63  create mode 100755 test/hooks\r
64 \r
65 diff --git a/test/hooks b/test/hooks\r
66 new file mode 100755\r
67 index 0000000..77e8569\r
68 --- /dev/null\r
69 +++ b/test/hooks\r
70 @@ -0,0 +1,104 @@\r
71 +#!/usr/bin/env bash\r
72 +test_description='hooks'\r
73 +. ./test-lib.sh\r
74 +\r
75 +HOOK_DIR=${MAIL_DIR}/.notmuch/hooks\r
76 +\r
77 +create_echo_hook () {\r
78 +    local TOKEN="${RANDOM}"\r
79 +    mkdir -p ${HOOK_DIR}\r
80 +    cat <<EOF >"${HOOK_DIR}/${1}"\r
81 +#!/bin/sh\r
82 +echo "${TOKEN}" > ${3}\r
83 +EOF\r
84 +    chmod +x "${HOOK_DIR}/${1}"\r
85 +    echo "${TOKEN}" > ${2}\r
86 +}\r
87 +\r
88 +create_failing_hook () {\r
89 +    mkdir -p ${HOOK_DIR}\r
90 +    cat <<EOF >"${HOOK_DIR}/${1}"\r
91 +#!/bin/sh\r
92 +exit 13\r
93 +EOF\r
94 +    chmod +x "${HOOK_DIR}/${1}"\r
95 +}\r
96 +\r
97 +rm_hooks () {\r
98 +    rm -rf ${HOOK_DIR}\r
99 +}\r
100 +\r
101 +# add a message to generate mail dir and database\r
102 +add_message\r
103 +\r
104 +test_begin_subtest "pre-new is run"\r
105 +rm_hooks\r
106 +generate_message\r
107 +create_echo_hook "pre-new" expected output\r
108 +notmuch new > /dev/null\r
109 +test_expect_equal_file expected output\r
110 +\r
111 +test_begin_subtest "post-new is run"\r
112 +rm_hooks\r
113 +generate_message\r
114 +create_echo_hook "post-new" expected output\r
115 +notmuch new > /dev/null\r
116 +test_expect_equal_file expected output\r
117 +\r
118 +test_begin_subtest "pre-new is run before post-new"\r
119 +rm_hooks\r
120 +generate_message\r
121 +create_echo_hook "pre-new" pre-new.expected pre-new.output\r
122 +create_echo_hook "post-new" post-new.expected post-new.output\r
123 +notmuch new > /dev/null\r
124 +test_expect_equal_file post-new.expected post-new.output\r
125 +\r
126 +test_begin_subtest "pre-new non-zero exit status (hook status)"\r
127 +rm_hooks\r
128 +generate_message\r
129 +create_failing_hook "pre-new"\r
130 +output=`notmuch new 2>&1`\r
131 +test_expect_equal "$output" "Error: pre-new hook failed with status 13"\r
132 +\r
133 +# depends on the previous subtest leaving broken hook behind\r
134 +test_expect_code 1 "pre-new non-zero exit status (notmuch status)" "notmuch new"\r
135 +\r
136 +# depends on the previous subtests leaving 1 new message behind\r
137 +test_begin_subtest "pre-new non-zero exit status aborts new"\r
138 +rm_hooks\r
139 +output=$(NOTMUCH_NEW)\r
140 +test_expect_equal "$output" "Added 1 new message to the database."\r
141 +\r
142 +test_begin_subtest "post-new non-zero exit status (hook status)"\r
143 +rm_hooks\r
144 +generate_message\r
145 +create_failing_hook "post-new"\r
146 +NOTMUCH_NEW 2>output.stderr >output\r
147 +cat output.stderr >> output\r
148 +echo "Added 1 new message to the database." > expected\r
149 +echo "Error: post-new hook failed with status 13" >> expected\r
150 +test_expect_equal_file expected output\r
151 +\r
152 +# depends on the previous subtest leaving broken hook behind\r
153 +test_expect_code 1 "post-new non-zero exit status (notmuch status)" "notmuch new"\r
154 +\r
155 +# test_begin_subtest "hook without executable permissions"\r
156 +rm_hooks\r
157 +mkdir -p ${HOOK_DIR}\r
158 +cat <<EOF >"${HOOK_DIR}/pre-new"\r
159 +#!/bin/sh\r
160 +echo foo\r
161 +EOF\r
162 +output=`notmuch new 2>&1`\r
163 +test_expect_code 1 "hook without executable permissions" "notmuch new"\r
164 +\r
165 +# test_begin_subtest "hook execution failure"\r
166 +rm_hooks\r
167 +mkdir -p ${HOOK_DIR}\r
168 +cat <<EOF >"${HOOK_DIR}/pre-new"\r
169 +no hashbang, execl fails\r
170 +EOF\r
171 +chmod +x "${HOOK_DIR}/pre-new"\r
172 +test_expect_code 1 "hook execution failure" "notmuch new"\r
173 +\r
174 +test_done\r
175 diff --git a/test/notmuch-test b/test/notmuch-test\r
176 index 53ce355..896f51f 100755\r
177 --- a/test/notmuch-test\r
178 +++ b/test/notmuch-test\r
179 @@ -48,6 +48,7 @@ TESTS="\r
180    search-folder-coherence\r
181    atomicity\r
182    python\r
183 +  hooks\r
184  "\r
185  TESTS=${NOTMUCH_TESTS:=$TESTS}\r
186  \r
187 -- \r
188 1.7.5.4\r
189 \r