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
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
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
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
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
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
58 Signed-off-by: Jani Nikula <jani@nikula.org>
\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
65 diff --git a/test/hooks b/test/hooks
\r
66 new file mode 100755
\r
67 index 0000000..77e8569
\r
71 +#!/usr/bin/env bash
\r
72 +test_description='hooks'
\r
75 +HOOK_DIR=${MAIL_DIR}/.notmuch/hooks
\r
77 +create_echo_hook () {
\r
78 + local TOKEN="${RANDOM}"
\r
79 + mkdir -p ${HOOK_DIR}
\r
80 + cat <<EOF >"${HOOK_DIR}/${1}"
\r
82 +echo "${TOKEN}" > ${3}
\r
84 + chmod +x "${HOOK_DIR}/${1}"
\r
85 + echo "${TOKEN}" > ${2}
\r
88 +create_failing_hook () {
\r
89 + mkdir -p ${HOOK_DIR}
\r
90 + cat <<EOF >"${HOOK_DIR}/${1}"
\r
94 + chmod +x "${HOOK_DIR}/${1}"
\r
98 + rm -rf ${HOOK_DIR}
\r
101 +# add a message to generate mail dir and database
\r
104 +test_begin_subtest "pre-new is run"
\r
107 +create_echo_hook "pre-new" expected output
\r
108 +notmuch new > /dev/null
\r
109 +test_expect_equal_file expected output
\r
111 +test_begin_subtest "post-new is run"
\r
114 +create_echo_hook "post-new" expected output
\r
115 +notmuch new > /dev/null
\r
116 +test_expect_equal_file expected output
\r
118 +test_begin_subtest "pre-new is run before post-new"
\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
126 +test_begin_subtest "pre-new non-zero exit status (hook status)"
\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
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
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
139 +output=$(NOTMUCH_NEW)
\r
140 +test_expect_equal "$output" "Added 1 new message to the database."
\r
142 +test_begin_subtest "post-new non-zero exit status (hook status)"
\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
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
155 +# test_begin_subtest "hook without executable permissions"
\r
157 +mkdir -p ${HOOK_DIR}
\r
158 +cat <<EOF >"${HOOK_DIR}/pre-new"
\r
162 +output=`notmuch new 2>&1`
\r
163 +test_expect_code 1 "hook without executable permissions" "notmuch new"
\r
165 +# test_begin_subtest "hook execution failure"
\r
167 +mkdir -p ${HOOK_DIR}
\r
168 +cat <<EOF >"${HOOK_DIR}/pre-new"
\r
169 +no hashbang, execl fails
\r
171 +chmod +x "${HOOK_DIR}/pre-new"
\r
172 +test_expect_code 1 "hook execution failure" "notmuch new"
\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
185 TESTS=${NOTMUCH_TESTS:=$TESTS}
\r