]> git.notmuchmail.org Git - notmuch/blob - test/T035-read-config.sh
CLI/count: switch to new configuration framework
[notmuch] / test / T035-read-config.sh
1 #!/usr/bin/env bash
2 test_description='Various options for reading configuration'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 backup_config () {
6     local test_name=$(basename $0 .sh)
7     cp ${NOTMUCH_CONFIG} notmuch-config-backup.${test_name}
8 }
9
10 xdg_config () {
11     local dir
12     local profile=${1:-default}
13     if [[ $profile != default ]]; then
14         export NOTMUCH_PROFILE=$profile
15     fi
16     backup_config
17     dir="${HOME}/.config/notmuch/${profile}"
18     rm -rf $dir
19     mkdir -p $dir
20     CONFIG_PATH=$dir/config
21     mv ${NOTMUCH_CONFIG} ${CONFIG_PATH}
22     unset NOTMUCH_CONFIG
23 }
24
25 restore_config () {
26     local test_name=$(basename $0 .sh)
27     export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
28     unset CONFIG_PATH
29     unset NOTMUCH_PROFILE
30     cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
31 }
32
33 add_email_corpus
34
35 test_begin_subtest "count with saved query from config file"
36 backup_config
37 query_name="test${RANDOM}"
38 notmuch count query:$query_name > OUTPUT
39 printf "\n[query]\n${query_name} = tag:inbox\n" >> notmuch-config
40 notmuch count query:$query_name >> OUTPUT
41 cat <<EOF > EXPECTED
42 0
43 52
44 EOF
45 restore_config
46 test_expect_equal_file EXPECTED OUTPUT
47
48 test_begin_subtest "count with saved query from config file (xdg)"
49 query_name="test${RANDOM}"
50 xdg_config
51 notmuch count query:$query_name > OUTPUT
52 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
53 notmuch count query:$query_name >> OUTPUT
54 cat <<EOF > EXPECTED
55 0
56 52
57 EOF
58 restore_config
59 test_expect_equal_file EXPECTED OUTPUT
60
61 test_begin_subtest "count with saved query from config file (xdg+profile)"
62 query_name="test${RANDOM}"
63 xdg_config work
64 notmuch count query:$query_name > OUTPUT
65 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
66 notmuch count query:$query_name >> OUTPUT
67 cat <<EOF > EXPECTED
68 0
69 52
70 EOF
71 restore_config
72 test_expect_equal_file EXPECTED OUTPUT
73
74
75 test_done