2 test_description='hooks'
5 HOOK_DIR=${MAIL_DIR}/.notmuch/hooks
8 local TOKEN="${RANDOM}"
10 cat <<EOF >"${HOOK_DIR}/${1}"
12 echo "${TOKEN}" > ${3}
14 chmod +x "${HOOK_DIR}/${1}"
15 echo "${TOKEN}" > ${2}
18 create_failing_hook () {
20 cat <<EOF >"${HOOK_DIR}/${1}"
24 chmod +x "${HOOK_DIR}/${1}"
31 # add a message to generate mail dir and database
34 test_begin_subtest "pre-new is run"
37 create_echo_hook "pre-new" expected output
38 notmuch new > /dev/null
39 test_expect_equal_file expected output
41 test_begin_subtest "post-new is run"
44 create_echo_hook "post-new" expected output
45 notmuch new > /dev/null
46 test_expect_equal_file expected output
48 test_begin_subtest "pre-new is run before post-new"
51 create_echo_hook "pre-new" pre-new.expected pre-new.output
52 create_echo_hook "post-new" post-new.expected post-new.output
53 notmuch new > /dev/null
54 test_expect_equal_file post-new.expected post-new.output
56 test_begin_subtest "pre-new non-zero exit status (hook status)"
59 create_failing_hook "pre-new"
60 output=`notmuch new 2>&1`
61 test_expect_equal "$output" "Error: pre-new hook failed with status 13"
63 # depends on the previous subtest leaving broken hook behind
64 test_expect_code 1 "pre-new non-zero exit status (notmuch status)" "notmuch new"
66 # depends on the previous subtests leaving 1 new message behind
67 test_begin_subtest "pre-new non-zero exit status aborts new"
70 test_expect_equal "$output" "Added 1 new message to the database."
72 test_begin_subtest "post-new non-zero exit status (hook status)"
75 create_failing_hook "post-new"
76 NOTMUCH_NEW 2>output.stderr >output
77 cat output.stderr >> output
78 echo "Added 1 new message to the database." > expected
79 echo "Error: post-new hook failed with status 13" >> expected
80 test_expect_equal_file expected output
82 # depends on the previous subtest leaving broken hook behind
83 test_expect_code 1 "post-new non-zero exit status (notmuch status)" "notmuch new"
85 # test_begin_subtest "hook without executable permissions"
88 cat <<EOF >"${HOOK_DIR}/pre-new"
92 output=`notmuch new 2>&1`
93 test_expect_code 1 "hook without executable permissions" "notmuch new"
95 # test_begin_subtest "hook execution failure"
98 cat <<EOF >"${HOOK_DIR}/pre-new"
99 no hashbang, execl fails
101 chmod +x "${HOOK_DIR}/pre-new"
102 test_expect_code 1 "hook execution failure" "notmuch new"