2 test_description='hooks'
3 . ./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_expect_code 1 "pre-new non-zero exit status (notmuch status)" "notmuch new"
75 # depends on the previous subtests leaving 1 new message behind
76 test_begin_subtest "pre-new non-zero exit status aborts new"
79 test_expect_equal "$output" "Added 1 new message to the database."
81 test_begin_subtest "post-new non-zero exit status (hook status)"
84 create_failing_hook "post-new"
85 NOTMUCH_NEW 2>output.stderr >output
86 cat output.stderr >> output
87 echo "Added 1 new message to the database." > expected
88 echo "Error: post-new hook failed with status 13" >> expected
89 test_expect_equal_file expected output
91 # depends on the previous subtest leaving broken hook behind
92 test_expect_code 1 "post-new non-zero exit status (notmuch status)" "notmuch new"
96 create_failing_hook "post-insert"
97 test_expect_success "post-insert hook does not affect insert status" \
98 "notmuch insert < \"$gen_msg_filename\" > /dev/null"
100 # test_begin_subtest "hook without executable permissions"
103 cat <<EOF >"${HOOK_DIR}/pre-new"
107 output=`notmuch new 2>&1`
108 test_expect_code 1 "hook without executable permissions" "notmuch new"
110 # test_begin_subtest "hook execution failure"
113 cat <<EOF >"${HOOK_DIR}/pre-new"
114 no hashbang, execl fails
116 chmod +x "${HOOK_DIR}/pre-new"
117 test_expect_code 1 "hook execution failure" "notmuch new"