]> git.notmuchmail.org Git - notmuch/blob - test/T030-config.sh
CLI: exit with error when load_config returns an error.
[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 cp notmuch-config initial-config
7
8 test_begin_subtest "Get string value"
9 test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
10
11 test_begin_subtest "Get list value"
12 cat <<EOF > EXPECTED
13 inbox
14 unread
15 EOF
16 notmuch config get new.tags | sort > OUTPUT
17 test_expect_equal_file EXPECTED OUTPUT
18
19 test_begin_subtest "Set string value"
20 notmuch config set foo.string "this is a string value"
21 test_expect_equal "$(notmuch config get foo.string)" "this is a string value"
22
23 test_begin_subtest "Set string value again"
24 notmuch config set foo.string "this is another string value"
25 test_expect_equal "$(notmuch config get foo.string)" "this is another string value"
26
27 test_begin_subtest "Set list value"
28 notmuch config set foo.list this "is a" "list value"
29 test_expect_equal "$(notmuch config get foo.list)" "\
30 this
31 is a
32 list value"
33
34 test_begin_subtest "Set list value again"
35 notmuch config set foo.list this "is another" "list value"
36 test_expect_equal "$(notmuch config get foo.list)" "\
37 this
38 is another
39 list value"
40
41 test_begin_subtest "Remove key"
42 notmuch config set foo.remove baz
43 notmuch config set foo.remove
44 test_expect_equal "$(notmuch config get foo.remove)" ""
45
46 test_begin_subtest "Remove non-existent key"
47 notmuch config set foo.nonexistent
48 test_expect_equal "$(notmuch config get foo.nonexistent)" ""
49
50 test_begin_subtest "List all items"
51 notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
52 cat <<EOF > EXPECTED
53 built_with.compact=something
54 built_with.field_processor=something
55 built_with.retry_lock=something
56 built_with.sexp_queries=something
57 database.autocommit=8000
58 database.mail_root=MAIL_DIR
59 database.path=MAIL_DIR
60 foo.list=this;is another;list value;
61 foo.string=this is another string value
62 index.as_text=
63 maildir.synchronize_flags=true
64 new.ignore=
65 new.tags=unread;inbox
66 search.exclude_tags=
67 user.name=Notmuch Test Suite
68 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
69 user.primary_email=test_suite@notmuchmail.org
70 EOF
71 test_expect_equal_file EXPECTED OUTPUT
72
73 test_begin_subtest "Round trip config item with leading spaces"
74 test_subtest_known_broken
75 notmuch config set foo.bar "  thing"
76 output=$(notmuch config get foo.bar)
77 test_expect_equal "${output}" "  thing"
78
79 test_begin_subtest "Round trip config item with leading tab"
80 test_subtest_known_broken
81 notmuch config set foo.bar "    thing"
82 output=$(notmuch config get foo.bar)
83 test_expect_equal "${output}" " thing"
84
85 test_begin_subtest "Round trip config item with embedded tab"
86 notmuch config set foo.bar "thing       other"
87 output=$(notmuch config get foo.bar)
88 test_expect_equal "${output}" "thing    other"
89
90 test_begin_subtest "Round trip config item with embedded backslash"
91 notmuch config set foo.bar 'thing\other'
92 output=$(notmuch config get foo.bar)
93 test_expect_equal "${output}" "thing\other"
94
95 test_begin_subtest "Round trip config item with embedded NL/CR"
96 notmuch config set foo.bar 'thing
97 \rother'
98 output=$(notmuch config get foo.bar)
99 test_expect_equal "${output}" "thing
100 \rother"
101
102 test_begin_subtest "Top level --config=FILE option"
103 cp "${NOTMUCH_CONFIG}" alt-config
104 notmuch --config=alt-config config set user.name "Another Name"
105 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
106     "Another Name"
107
108 test_begin_subtest "Top level --config:FILE option"
109 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
110     "Another Name"
111
112 test_begin_subtest "Top level --config<space>FILE option"
113 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
114     "Another Name"
115
116 test_begin_subtest "Top level --config=FILE option changed the right file"
117 test_expect_equal "$(notmuch config get user.name)" \
118     "Notmuch Test Suite"
119
120 test_begin_subtest "Read config file through a symlink"
121 ln -s alt-config alt-config-link
122 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
123     "Another Name"
124
125 test_begin_subtest "Write config file through a symlink"
126 notmuch --config=alt-config-link config set user.name "Link Name"
127 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
128     "Link Name"
129
130 test_begin_subtest "Writing config file through symlink follows symlink"
131 test_expect_equal "$(readlink alt-config-link)" "alt-config"
132
133 test_begin_subtest "Round trip arbitrary key"
134 key=g${RANDOM}.m${RANDOM}
135 value=${RANDOM}
136 notmuch config set ${key} ${value}
137 output=$(notmuch config get ${key})
138 test_expect_equal "${output}" "${value}"
139
140 test_begin_subtest "Clear arbitrary key"
141 notmuch config set ${key}
142 output=$(notmuch config get ${key})
143 test_expect_equal "${output}" ""
144
145 db_path=${HOME}/database-path
146
147 test_begin_subtest "Absolute database path returned"
148 notmuch config set database.path ${HOME}/Maildir
149 test_expect_equal "$(notmuch config get database.path)" \
150                   "${HOME}/Maildir"
151
152 ln -s `pwd`/mail home/Maildir
153 add_email_corpus
154 test_begin_subtest "Relative database path expanded"
155 notmuch config set database.path Maildir
156 path=$(notmuch config get database.path | notmuch_dir_sanitize)
157 count=$(notmuch count '*')
158 test_expect_equal "${path} ${count}" \
159                   "CWD/home/Maildir 52"
160
161 test_begin_subtest "Add config to database"
162 notmuch new
163 key=g${RANDOM}.m${RANDOM}
164 value=${RANDOM}
165 notmuch config set --database ${key} ${value}
166 notmuch dump --include=config > OUTPUT
167 cat <<EOF > EXPECTED
168 #notmuch-dump batch-tag:3 config
169 #@ ${key} ${value}
170 EOF
171 test_expect_equal_file EXPECTED OUTPUT
172
173 test_begin_subtest "Roundtrip config to/from database"
174 notmuch new
175 key=g${RANDOM}.m${RANDOM}
176 value=${RANDOM}
177 notmuch config set --database ${key} ${value}
178 output=$(notmuch config get ${key})
179 test_expect_equal "${output}" "${value}"
180
181 test_begin_subtest "set built_with.* yields error"
182 test_expect_code 1 "notmuch config set built_with.compact false"
183
184 test_begin_subtest "get built_with.{compact,field_processor} prints true"
185 for key in compact field_processor; do
186     notmuch config get built_with.${key}
187 done > OUTPUT
188 cat <<EOF > EXPECTED
189 true
190 true
191 EOF
192 test_expect_equal_file EXPECTED OUTPUT
193
194 test_begin_subtest "get built_with.nonexistent prints false"
195 output=$(notmuch config get built_with.nonexistent)
196 test_expect_equal "$output" "false"
197
198 test_begin_subtest "Bad utf8 reported as error"
199 cp initial-config bad-config
200 printf '[query]\nq3=from:\xff\n' >>bad-config
201 test_expect_code 1 "notmuch --config=./bad-config config list"
202
203 test_done