]> git.cworth.org Git - notmuch/blob - test/T405-external.sh
test: define test_private_C
[notmuch] / test / T405-external.sh
1 #!/usr/bin/env bash
2 test_description='hooks'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 create_echo_script () {
6     local TOKEN="${RANDOM}"
7     mkdir -p ${BIN_DIR}
8     cat <<EOF >"${BIN_DIR}/${1}"
9 #!/bin/sh
10 echo "${TOKEN}" > ${3}
11 EOF
12     chmod +x "${BIN_DIR}/${1}"
13     echo "${TOKEN}" > ${2}
14 }
15
16 create_printenv_script () {
17     mkdir -p ${BIN_DIR}
18     cat <<EOF >"${BIN_DIR}/${1}"
19 #!/bin/sh
20 printenv "${2}" > "${3}"
21 EOF
22     chmod +x "${BIN_DIR}/${1}"
23 }
24
25 # add a message to generate mail dir and database
26 add_message
27
28 BIN_DIR=`pwd`/bin
29 PATH=$BIN_DIR:$PATH
30
31 test_begin_subtest "'notmuch foo' runs notmuch-foo"
32 rm -rf ${BIN_DIR}
33 create_echo_script "notmuch-foo" EXPECTED OUTPUT $HOOK_DIR
34 notmuch foo
35 test_expect_equal_file_nonempty EXPECTED OUTPUT
36
37 create_printenv_script "notmuch-printenv" NOTMUCH_CONFIG OUTPUT
38
39 test_begin_subtest "NOTMUCH_CONFIG is set"
40 notmuch printenv
41 cat <<EOF > EXPECTED
42 ${NOTMUCH_CONFIG}
43 EOF
44 test_expect_equal_file_nonempty EXPECTED OUTPUT
45
46 test_begin_subtest "NOTMUCH_CONFIG is set by --config"
47 cp "${NOTMUCH_CONFIG}" "${NOTMUCH_CONFIG}.alternate"
48 cat <<EOF > EXPECTED
49 ${NOTMUCH_CONFIG}.alternate
50 EOF
51 notmuch --config "${NOTMUCH_CONFIG}.alternate" printenv
52 test_expect_equal_file_nonempty EXPECTED OUTPUT
53
54 test_done