]> git.cworth.org Git - notmuch/blob - test/T035-read-config.sh
Merge tag '0.32_rc2'
[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 cat <<EOF > EXPECTED
75 Before:
76 #notmuch-dump batch-tag:3 tags
77
78 After:
79 #notmuch-dump batch-tag:3 tags
80 +attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
81 +attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
82 +inbox +signed +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
83 +inbox +signed +unread -- id:20091117203301.GV3165@dottiness.seas.harvard.edu
84 +inbox +signed +unread -- id:20091118002059.067214ed@hikari
85 +inbox +signed +unread -- id:20091118005040.GA25380@dottiness.seas.harvard.edu
86 +inbox +signed +unread -- id:87iqd9rn3l.fsf@vertex.dottedmag
87 EOF
88
89 test_begin_subtest "dump with saved query from config file"
90 backup_config
91 query_name="test${RANDOM}"
92 CONFIG_PATH=notmuch-config
93 printf "Before:\n" > OUTPUT
94 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
95 printf "\nAfter:\n" >> OUTPUT
96 printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
97 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
98 restore_config
99 test_expect_equal_file EXPECTED OUTPUT
100
101 test_begin_subtest "dump with saved query from config file (xdg)"
102 backup_config
103 query_name="test${RANDOM}"
104 xdg_config
105 printf "Before:\n" > OUTPUT
106 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
107 printf "\nAfter:\n" >> OUTPUT
108 printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
109 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
110 restore_config
111 test_expect_equal_file EXPECTED OUTPUT
112
113 test_begin_subtest "dump with saved query from config file (xdg+profile)"
114 backup_config
115 query_name="test${RANDOM}"
116 xdg_config work
117 printf "Before:\n" > OUTPUT
118 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
119 printf "\nAfter:\n" >> OUTPUT
120 printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
121 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
122 restore_config
123 test_expect_equal_file EXPECTED OUTPUT
124
125 test_begin_subtest "restore with xdg config"
126 backup_config
127 notmuch dump '*' > EXPECTED
128 notmuch tag -inbox '*'
129 xdg_config
130 notmuch restore --input=EXPECTED
131 notmuch dump > OUTPUT
132 restore_config
133 test_expect_equal_file EXPECTED OUTPUT
134
135 test_begin_subtest "restore with xdg+profile config"
136 backup_config
137 notmuch dump '*' > EXPECTED
138 notmuch tag -inbox '*'
139 xdg_config work
140 notmuch restore --input=EXPECTED
141 notmuch dump > OUTPUT
142 restore_config
143 test_expect_equal_file EXPECTED OUTPUT
144
145 test_begin_subtest "Insert message with custom new.tags (xdg)"
146 backup_config
147 xdg_config
148 tag=test${RANDOM}
149 notmuch --config=${CONFIG_PATH} config set new.tags $tag
150 generate_message \
151     "[subject]=\"insert-subject\"" \
152     "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
153     "[body]=\"insert-message\""
154 mkdir -p ${MAIL_DIR}/{cur,new,tmp}
155 notmuch insert < "$gen_msg_filename"
156 notmuch dump id:$gen_msg_id > OUTPUT
157 cat <<EOF > EXPECTED
158 #notmuch-dump batch-tag:3 config,properties,tags
159 +$tag -- id:$gen_msg_id
160 EOF
161 restore_config
162 test_expect_equal_file EXPECTED OUTPUT
163
164 test_begin_subtest "Insert message with custom new.tags (xdg+profile)"
165 backup_config
166 tag=test${RANDOM}
167 xdg_config $tag
168 notmuch --config=${CONFIG_PATH} config set new.tags $tag
169 generate_message \
170     "[subject]=\"insert-subject\"" \
171     "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
172     "[body]=\"insert-message\""
173 mkdir -p ${MAIL_DIR}/{cur,new,tmp}
174 notmuch insert < "$gen_msg_filename"
175 notmuch dump id:$gen_msg_id > OUTPUT
176 cat <<EOF > EXPECTED
177 #notmuch-dump batch-tag:3 config,properties,tags
178 +$tag -- id:$gen_msg_id
179 EOF
180 restore_config
181 test_expect_equal_file EXPECTED OUTPUT
182
183 test_begin_subtest "reindex with saved query from config file"
184 backup_config
185 query_name="test${RANDOM}"
186 count1=$(notmuch count --lastmod '*' | cut -f3)
187 printf "\n[query]\n${query_name} = tag:inbox\n" >> notmuch-config
188 notmuch reindex query:$query_name
189 count2=$(notmuch count --lastmod '*' | cut -f3)
190 restore_config
191 test_expect_success "test '$count2 -gt $count1'"
192
193 test_begin_subtest "reindex with saved query from config file (xdg)"
194 query_name="test${RANDOM}"
195 count1=$(notmuch count --lastmod '*' | cut -f3)
196 xdg_config
197 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
198 notmuch reindex query:$query_name
199 count2=$(notmuch count --lastmod '*' | cut -f3)
200 restore_config
201 test_expect_success "test '$count2 -gt $count1'"
202
203 test_begin_subtest "reindex with saved query from config file (xdg+profile)"
204 query_name="test${RANDOM}"
205 count1=$(notmuch count --lastmod '*' | cut -f3)
206 xdg_config $query_name
207 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
208 notmuch reindex query:$query_name
209 count2=$(notmuch count --lastmod '*' | cut -f3)
210 restore_config
211 test_expect_success "test '$count2 -gt $count1'"
212
213
214
215 add_message '[from]="Sender <sender@example.com>"' \
216              [to]=test_suite@notmuchmail.org \
217             '[cc]="Other Parties <cc@example.com>"' \
218              [subject]=notmuch-reply-test \
219             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
220             '[body]="reply with CC"'
221
222 cat <<EOF > EXPECTED
223 Before:
224 After:
225 From: Notmuch Test Suite <test_suite@notmuchmail.org>
226 Subject: Re: notmuch-reply-test
227 To: Sender <sender@example.com>
228 Cc: Other Parties <cc@example.com>
229 In-Reply-To: <${gen_msg_id}>
230 References: <${gen_msg_id}>
231
232 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
233 > reply with CC
234 EOF
235
236 test_begin_subtest "reply with saved query from config file"
237 backup_config
238 query_name="test${RANDOM}"
239 printf "Before:\n" > OUTPUT
240 notmuch reply query:$query_name 2>&1 >> OUTPUT
241 printf "\n[query]\n${query_name} = id:${gen_msg_id}\n" >> notmuch-config
242 printf "After:\n" >> OUTPUT
243 notmuch reply query:$query_name >> OUTPUT
244 restore_config
245 test_expect_equal_file EXPECTED OUTPUT
246
247 test_begin_subtest "reply with saved query from config file (xdg)"
248 backup_config
249 query_name="test${RANDOM}"
250 xdg_config
251 printf "Before:\n" > OUTPUT
252 notmuch reply query:$query_name 2>&1 >> OUTPUT
253 printf "\n[query]\n${query_name} = id:${gen_msg_id}\n" >> ${CONFIG_PATH}
254 printf "After:\n" >> OUTPUT
255 notmuch reply query:$query_name >> OUTPUT
256 restore_config
257 test_expect_equal_file EXPECTED OUTPUT
258
259 test_begin_subtest "reply with saved query from config file (xdg+profile)"
260 backup_config
261 query_name="test${RANDOM}"
262 xdg_config $query_name
263 printf "Before:\n" > OUTPUT
264 notmuch reply query:$query_name 2>&1 >> OUTPUT
265 printf "\n[query]\n${query_name} = id:${gen_msg_id}\n" >> ${CONFIG_PATH}
266 printf "After:\n" >> OUTPUT
267 notmuch reply query:$query_name >> OUTPUT
268 restore_config
269 test_expect_equal_file EXPECTED OUTPUT
270
271 backup_database
272 test_begin_subtest "search with alternate config"
273 notmuch tag -- +foobar17 '*'
274 cp notmuch-config alt-config
275 notmuch --config=alt-config config set search.exclude_tags foobar17
276 output=$(notmuch --config=alt-config count '*')
277 test_expect_equal "$output" "0"
278 restore_database
279
280 cat <<EOF > EXPECTED
281 Before:
282 After:
283 thread:XXX   2009-11-18 [1/2] Carl Worth| Alex Botero-Lowry; [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread)
284 thread:XXX   2009-11-18 [1/2] Carl Worth| Ingmar Vanhassel; [notmuch] [PATCH] Typsos (inbox unread)
285 thread:XXX   2009-11-18 [1/3] Carl Worth| Adrian Perez de Castro, Keith Packard; [notmuch] Introducing myself (inbox signed unread)
286 thread:XXX   2009-11-18 [1/3] Carl Worth| Israel Herraiz, Keith Packard; [notmuch] New to the list (inbox unread)
287 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
288 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
289 thread:XXX   2009-11-18 [1/3(4)] Carl Worth| Aron Griffis, Keith Packard; [notmuch] archive (inbox unread)
290 thread:XXX   2009-11-18 [1/2] Carl Worth| Keith Packard; [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)
291 thread:XXX   2009-11-18 [1/7] Carl Worth| Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard; [notmuch] Working with Maildir storage? (inbox signed unread)
292 thread:XXX   2009-11-18 [2/5] Carl Worth| Mikhail Gusarov, Keith Packard; [notmuch] [PATCH 1/2] Close message file after parsing message headers (inbox unread)
293 thread:XXX   2009-11-17 [1/2] Carl Worth| Alex Botero-Lowry; [notmuch] preliminary FreeBSD support (attachment inbox unread)
294 EOF
295
296 test_begin_subtest "search with saved query from config file"
297 query_name="test${RANDOM}"
298 backup_config
299 printf "Before:\n" > OUTPUT
300 notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
301 printf "\n[query]\n${query_name} = from:cworth\n" >> notmuch-config
302 printf "After:\n" >> OUTPUT
303 notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
304 restore_config
305 test_expect_equal_file EXPECTED OUTPUT
306
307 test_begin_subtest "search with saved query from config file (xdg)"
308 query_name="test${RANDOM}"
309 xdg_config
310 printf "Before:\n" > OUTPUT
311 notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
312 printf "\n[query]\n${query_name} = from:cworth\n" >> ${CONFIG_PATH}
313 printf "After:\n" >> OUTPUT
314 notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
315 restore_config
316 test_expect_equal_file EXPECTED OUTPUT
317
318 test_begin_subtest "search with saved query from config file (xdg + profile)"
319 query_name="test${RANDOM}"
320 xdg_config $query_name
321 printf "Before:\n" > OUTPUT
322 notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
323 printf "\n[query]\n${query_name} = from:cworth\n" >> ${CONFIG_PATH}
324 printf "After:\n" >> OUTPUT
325 notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
326 restore_config
327 test_expect_equal_file EXPECTED OUTPUT
328
329 cat <<EOF > EXPECTED
330 Before:
331 After:
332 Alex Botero-Lowry <alex.boterolowry@gmail.com>
333 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
334 François Boulogne <boulogne.f@gmail.com>
335 Jjgod Jiang <gzjjgod@gmail.com>
336 EOF
337
338 test_begin_subtest "address: saved query from config file"
339 backup_config
340 query_name="test${RANDOM}"
341 printf "Before:\n" > OUTPUT
342 notmuch address --deduplicate=no --output=sender query:$query_name 2>&1 | sort >> OUTPUT
343 printf "\n[query]\n${query_name} = from:gmail.com\n" >> notmuch-config
344 printf "After:\n" >> OUTPUT
345 notmuch address --output=sender query:$query_name | sort >> OUTPUT
346 restore_config
347 test_expect_equal_file EXPECTED OUTPUT
348
349 test_begin_subtest "address: saved query from config file (xdg)"
350 query_name="test${RANDOM}"
351 xdg_config
352 printf "Before:\n" > OUTPUT
353 notmuch address --deduplicate=no --output=sender query:$query_name 2>&1 | sort >> OUTPUT
354 printf "\n[query]\n${query_name} = from:gmail.com\n" >> ${CONFIG_PATH}
355 printf "After:\n" >> OUTPUT
356 notmuch address --output=sender query:$query_name | sort >> OUTPUT
357 restore_config
358 test_expect_equal_file EXPECTED OUTPUT
359
360 test_begin_subtest "address: saved query from config file (xdg+profile)"
361 query_name="test${RANDOM}"
362 xdg_config $query_name
363 printf "Before:\n" > OUTPUT
364 notmuch address --deduplicate=no --output=sender query:$query_name 2>&1 | sort >> OUTPUT
365 printf "\n[query]\n${query_name} = from:gmail.com\n" >> ${CONFIG_PATH}
366 printf "After:\n" >> OUTPUT
367 notmuch address --output=sender query:$query_name | sort >> OUTPUT
368 restore_config
369 test_expect_equal_file EXPECTED OUTPUT
370
371 test_begin_subtest "show with alternate config"
372 backup_database
373 cp notmuch-config alt-config
374 notmuch --config=alt-config config set search.exclude_tags foobar17
375 notmuch tag -- +foobar17 '*'
376 output=$(notmuch --config=alt-config show '*' && echo OK)
377 restore_database
378 test_expect_equal "$output" "OK"
379
380 test_begin_subtest "show with alternate config (xdg)"
381 backup_database
382 notmuch tag -- +foobar17 '*'
383 xdg_config
384 notmuch --config=${CONFIG_PATH} config set search.exclude_tags foobar17
385 output=$(notmuch show '*' && echo OK)
386 restore_database
387 restore_config
388 test_expect_equal "$output" "OK"
389
390 test_begin_subtest "show with alternate config (xdg+profile)"
391 backup_database
392 notmuch tag -- +foobar17 '*'
393 xdg_config foobar17
394 notmuch --config=${CONFIG_PATH} config set search.exclude_tags foobar17
395 output=$(notmuch show '*' && echo OK)
396 restore_database
397 restore_config
398 test_expect_equal "$output" "OK"
399
400 # reset to known state
401 add_email_corpus
402
403 test_begin_subtest "tag with saved query from config file"
404 backup_config
405 query_name="test${RANDOM}"
406 tag_name="tag${RANDOM}"
407 notmuch count query:$query_name > OUTPUT
408 printf "\n[query]\n${query_name} = tag:inbox\n" >> notmuch-config
409 notmuch tag +$tag_name -- query:${query_name}
410 notmuch count tag:$tag_name >> OUTPUT
411 cat <<EOF > EXPECTED
412 0
413 52
414 EOF
415 restore_config
416 test_expect_equal_file EXPECTED OUTPUT
417
418 test_begin_subtest "tag with saved query from config file (xdg)"
419 xdg_config
420 query_name="test${RANDOM}"
421 tag_name="tag${RANDOM}"
422 notmuch count query:$query_name > OUTPUT
423 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
424 notmuch tag +$tag_name -- query:${query_name}
425 notmuch count tag:$tag_name >> OUTPUT
426 cat <<EOF > EXPECTED
427 0
428 52
429 EOF
430 restore_config
431 test_expect_equal_file EXPECTED OUTPUT
432
433 test_begin_subtest "tag with saved query from config file (xdg+profile)"
434 query_name="test${RANDOM}"
435 xdg_config ${query_name}
436 tag_name="tag${RANDOM}"
437 notmuch count query:$query_name > OUTPUT
438 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
439 notmuch tag +$tag_name -- query:${query_name}
440 notmuch count tag:$tag_name >> OUTPUT
441 cat <<EOF > EXPECTED
442 0
443 52
444 EOF
445 restore_config
446 test_expect_equal_file EXPECTED OUTPUT
447
448 test_begin_subtest "running compact (xdg)"
449 xdg_config
450 notmuch compact
451 output=$(notmuch count '*')
452 restore_config
453 test_expect_equal "52" "$output"
454
455 test_begin_subtest "running compact (xdg + profile)"
456 xdg_config ${RANDOM}
457 notmuch compact
458 output=$(notmuch count '*')
459 restore_config
460 test_expect_equal "52" "$output"
461
462 test_begin_subtest "run notmuch-new (xdg)"
463 xdg_config
464 generate_message
465 output=$(NOTMUCH_NEW --debug)
466 restore_config
467 test_expect_equal "$output" "Added 1 new message to the database."
468
469 test_begin_subtest "run notmuch-new (xdg + profile)"
470 xdg_config ${RANDOM}
471 generate_message
472 output=$(NOTMUCH_NEW --debug)
473 restore_config
474 test_expect_equal "$output" "Added 1 new message to the database."
475
476 test_done