2 test_description='hooks'
3 . $(dirname "$0")/test-lib.sh || exit 1
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
33 # create maildir structure for notmuch-insert
34 mkdir -p "$MAIL_DIR"/{cur,new,tmp}
36 test_begin_subtest "pre-new is run"
39 create_echo_hook "pre-new" expected output
40 notmuch new > /dev/null
41 test_expect_equal_file expected output
43 test_begin_subtest "post-new is run"
46 create_echo_hook "post-new" expected output
47 notmuch new > /dev/null
48 test_expect_equal_file expected output
50 test_begin_subtest "post-insert hook is run"
53 create_echo_hook "post-insert" expected output
54 notmuch insert < "$gen_msg_filename"
55 test_expect_equal_file expected output
57 test_begin_subtest "pre-new is run before post-new"
60 create_echo_hook "pre-new" pre-new.expected pre-new.output
61 create_echo_hook "post-new" post-new.expected post-new.output
62 notmuch new > /dev/null
63 test_expect_equal_file post-new.expected post-new.output
65 test_begin_subtest "pre-new non-zero exit status (hook status)"
68 create_failing_hook "pre-new"
69 output=`notmuch new 2>&1`
70 test_expect_equal "$output" "Error: pre-new hook failed with status 13"
72 # depends on the previous subtest leaving broken hook behind
73 test_begin_subtest "pre-new non-zero exit status (notmuch status)"
74 test_expect_code 1 "notmuch new"
76 # depends on the previous subtests leaving 1 new message behind
77 test_begin_subtest "pre-new non-zero exit status aborts new"
80 test_expect_equal "$output" "Added 1 new message to the database."
82 test_begin_subtest "post-new non-zero exit status (hook status)"
85 create_failing_hook "post-new"
86 NOTMUCH_NEW 2>output.stderr >output
87 cat output.stderr >> output
88 echo "Added 1 new message to the database." > expected
89 echo "Error: post-new hook failed with status 13" >> expected
90 test_expect_equal_file expected output
92 # depends on the previous subtest leaving broken hook behind
93 test_begin_subtest "post-new non-zero exit status (notmuch status)"
94 test_expect_code 1 "notmuch new"
96 test_begin_subtest "post-insert hook does not affect insert status"
99 create_failing_hook "post-insert"
100 test_expect_success "notmuch insert < \"$gen_msg_filename\" > /dev/null"
102 test_begin_subtest "hook without executable permissions"
105 cat <<EOF >"${HOOK_DIR}/pre-new"
109 output=`notmuch new 2>&1`
110 test_expect_code 1 "notmuch new"
112 test_begin_subtest "hook execution failure"
115 cat <<EOF >"${HOOK_DIR}/pre-new"
116 no hashbang, execl fails
118 chmod +x "${HOOK_DIR}/pre-new"
119 test_expect_code 1 "notmuch new"