Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 839D2429E31 for ; Thu, 8 Dec 2011 14:48:49 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C9MVd3t3C19l for ; Thu, 8 Dec 2011 14:48:47 -0800 (PST) Received: from mail-ey0-f181.google.com (mail-ey0-f181.google.com [209.85.215.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 5B882429E2E for ; Thu, 8 Dec 2011 14:48:47 -0800 (PST) Received: by mail-ey0-f181.google.com with SMTP id l13so1711208eaa.26 for ; Thu, 08 Dec 2011 14:48:47 -0800 (PST) Received: by 10.213.22.197 with SMTP id o5mr1312547ebb.55.1323384527075; Thu, 08 Dec 2011 14:48:47 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id 58sm23179839eet.11.2011.12.08.14.48.45 (version=SSLv3 cipher=OTHER); Thu, 08 Dec 2011 14:48:46 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v4 3/3] test: add tests for hooks Date: Fri, 9 Dec 2011 00:48:31 +0200 Message-Id: <8cd10b58761ace1834368427182925c1c32e9f1b.1323384304.git.jani@nikula.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org> In-Reply-To: References: X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Dec 2011 22:48:49 -0000 Signed-off-by: Jani Nikula --- test/hooks | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test/notmuch-test | 1 + 2 files changed, 105 insertions(+), 0 deletions(-) create mode 100755 test/hooks diff --git a/test/hooks b/test/hooks new file mode 100755 index 0000000..77e8569 --- /dev/null +++ b/test/hooks @@ -0,0 +1,104 @@ +#!/usr/bin/env bash +test_description='hooks' +. ./test-lib.sh + +HOOK_DIR=${MAIL_DIR}/.notmuch/hooks + +create_echo_hook () { + local TOKEN="${RANDOM}" + mkdir -p ${HOOK_DIR} + cat <"${HOOK_DIR}/${1}" +#!/bin/sh +echo "${TOKEN}" > ${3} +EOF + chmod +x "${HOOK_DIR}/${1}" + echo "${TOKEN}" > ${2} +} + +create_failing_hook () { + mkdir -p ${HOOK_DIR} + cat <"${HOOK_DIR}/${1}" +#!/bin/sh +exit 13 +EOF + chmod +x "${HOOK_DIR}/${1}" +} + +rm_hooks () { + rm -rf ${HOOK_DIR} +} + +# add a message to generate mail dir and database +add_message + +test_begin_subtest "pre-new is run" +rm_hooks +generate_message +create_echo_hook "pre-new" expected output +notmuch new > /dev/null +test_expect_equal_file expected output + +test_begin_subtest "post-new is run" +rm_hooks +generate_message +create_echo_hook "post-new" expected output +notmuch new > /dev/null +test_expect_equal_file expected output + +test_begin_subtest "pre-new is run before post-new" +rm_hooks +generate_message +create_echo_hook "pre-new" pre-new.expected pre-new.output +create_echo_hook "post-new" post-new.expected post-new.output +notmuch new > /dev/null +test_expect_equal_file post-new.expected post-new.output + +test_begin_subtest "pre-new non-zero exit status (hook status)" +rm_hooks +generate_message +create_failing_hook "pre-new" +output=`notmuch new 2>&1` +test_expect_equal "$output" "Error: pre-new hook failed with status 13" + +# depends on the previous subtest leaving broken hook behind +test_expect_code 1 "pre-new non-zero exit status (notmuch status)" "notmuch new" + +# depends on the previous subtests leaving 1 new message behind +test_begin_subtest "pre-new non-zero exit status aborts new" +rm_hooks +output=$(NOTMUCH_NEW) +test_expect_equal "$output" "Added 1 new message to the database." + +test_begin_subtest "post-new non-zero exit status (hook status)" +rm_hooks +generate_message +create_failing_hook "post-new" +NOTMUCH_NEW 2>output.stderr >output +cat output.stderr >> output +echo "Added 1 new message to the database." > expected +echo "Error: post-new hook failed with status 13" >> expected +test_expect_equal_file expected output + +# depends on the previous subtest leaving broken hook behind +test_expect_code 1 "post-new non-zero exit status (notmuch status)" "notmuch new" + +# test_begin_subtest "hook without executable permissions" +rm_hooks +mkdir -p ${HOOK_DIR} +cat <"${HOOK_DIR}/pre-new" +#!/bin/sh +echo foo +EOF +output=`notmuch new 2>&1` +test_expect_code 1 "hook without executable permissions" "notmuch new" + +# test_begin_subtest "hook execution failure" +rm_hooks +mkdir -p ${HOOK_DIR} +cat <"${HOOK_DIR}/pre-new" +no hashbang, execl fails +EOF +chmod +x "${HOOK_DIR}/pre-new" +test_expect_code 1 "hook execution failure" "notmuch new" + +test_done diff --git a/test/notmuch-test b/test/notmuch-test index 53ce355..896f51f 100755 --- a/test/notmuch-test +++ b/test/notmuch-test @@ -48,6 +48,7 @@ TESTS=" search-folder-coherence atomicity python + hooks " TESTS=${NOTMUCH_TESTS:=$TESTS} -- 1.7.5.4