]> git.notmuchmail.org Git - notmuch/blob - test/T030-config.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T030-config.sh
1 #!/usr/bin/env bash
2
3 test_description='"notmuch config"'
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 test_begin_subtest "Get string value"
7 test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
8
9 test_begin_subtest "Get list value"
10 cat <<EOF > EXPECTED
11 inbox
12 unread
13 EOF
14 notmuch config get new.tags | sort > OUTPUT
15 test_expect_equal_file EXPECTED OUTPUT
16
17 test_begin_subtest "Set string value"
18 notmuch config set foo.string "this is a string value"
19 test_expect_equal "$(notmuch config get foo.string)" "this is a string value"
20
21 test_begin_subtest "Set string value again"
22 notmuch config set foo.string "this is another string value"
23 test_expect_equal "$(notmuch config get foo.string)" "this is another string value"
24
25 test_begin_subtest "Set list value"
26 notmuch config set foo.list this "is a" "list value"
27 test_expect_equal "$(notmuch config get foo.list)" "\
28 this
29 is a
30 list value"
31
32 test_begin_subtest "Set list value again"
33 notmuch config set foo.list this "is another" "list value"
34 test_expect_equal "$(notmuch config get foo.list)" "\
35 this
36 is another
37 list value"
38
39 test_begin_subtest "Remove key"
40 notmuch config set foo.remove baz
41 notmuch config set foo.remove
42 test_expect_equal "$(notmuch config get foo.remove)" ""
43
44 test_begin_subtest "Remove non-existent key"
45 notmuch config set foo.nonexistent
46 test_expect_equal "$(notmuch config get foo.nonexistent)" ""
47
48 test_begin_subtest "List all items"
49 notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
50 cat <<EOF > EXPECTED
51 built_with.compact=something
52 built_with.field_processor=something
53 built_with.retry_lock=something
54 database.mail_root=MAIL_DIR
55 database.path=MAIL_DIR
56 foo.list=this;is another;list value;
57 foo.string=this is another string value
58 maildir.synchronize_flags=true
59 new.ignore=
60 new.tags=unread;inbox
61 search.exclude_tags=
62 user.name=Notmuch Test Suite
63 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
64 user.primary_email=test_suite@notmuchmail.org
65 EOF
66 test_expect_equal_file EXPECTED OUTPUT
67
68 test_begin_subtest "Top level --config=FILE option"
69 cp "${NOTMUCH_CONFIG}" alt-config
70 notmuch --config=alt-config config set user.name "Another Name"
71 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
72     "Another Name"
73
74 test_begin_subtest "Top level --config:FILE option"
75 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
76     "Another Name"
77
78 test_begin_subtest "Top level --config<space>FILE option"
79 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
80     "Another Name"
81
82 test_begin_subtest "Top level --config=FILE option changed the right file"
83 test_expect_equal "$(notmuch config get user.name)" \
84     "Notmuch Test Suite"
85
86 test_begin_subtest "Read config file through a symlink"
87 ln -s alt-config alt-config-link
88 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
89     "Another Name"
90
91 test_begin_subtest "Write config file through a symlink"
92 notmuch --config=alt-config-link config set user.name "Link Name"
93 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
94     "Link Name"
95
96 test_begin_subtest "Writing config file through symlink follows symlink"
97 test_expect_equal "$(readlink alt-config-link)" "alt-config"
98
99 test_begin_subtest "Round trip arbitrary key"
100 key=g${RANDOM}.m${RANDOM}
101 value=${RANDOM}
102 notmuch config set ${key} ${value}
103 output=$(notmuch config get ${key})
104 test_expect_equal "${output}" "${value}"
105
106 test_begin_subtest "Clear arbitrary key"
107 notmuch config set ${key}
108 output=$(notmuch config get ${key})
109 test_expect_equal "${output}" ""
110
111 db_path=${HOME}/database-path
112
113 test_begin_subtest "Absolute database path returned"
114 notmuch config set database.path ${HOME}/Maildir
115 test_expect_equal "$(notmuch config get database.path)" \
116                   "${HOME}/Maildir"
117
118 ln -s `pwd`/mail home/Maildir
119 add_email_corpus
120 test_begin_subtest "Relative database path expanded in open"
121 notmuch config set database.path Maildir
122 path=$(notmuch config get database.path)
123 count=$(notmuch count '*')
124 test_expect_equal "${path} ${count}" \
125                   "Maildir 52"
126
127 test_begin_subtest "Add config to database"
128 notmuch new
129 key=g${RANDOM}.m${RANDOM}
130 value=${RANDOM}
131 notmuch config set --database ${key} ${value}
132 notmuch dump --include=config > OUTPUT
133 cat <<EOF > EXPECTED
134 #notmuch-dump batch-tag:3 config
135 #@ ${key} ${value}
136 EOF
137 test_expect_equal_file EXPECTED OUTPUT
138
139 test_begin_subtest "Roundtrip config to/from database"
140 notmuch new
141 key=g${RANDOM}.m${RANDOM}
142 value=${RANDOM}
143 notmuch config set --database ${key} ${value}
144 output=$(notmuch config get ${key})
145 test_expect_equal "${output}" "${value}"
146
147 test_done