2 test_description="library config API"
4 . $(dirname "$0")/test-lib.sh || exit 1
8 _libconfig_sanitize() {
9 ${NOTMUCH_PYTHON} /dev/fd/3 3<<'EOF'
10 import os, sys, pwd, socket
12 pw = pwd.getpwuid(os.getuid())
14 name = pw.pw_gecos.partition(",")[0]
18 l = l.replace(user, "USERNAME", 1)
20 l = l.replace("'" + name, "'USER_FULL_NAME", 1)
26 #include <notmuch-test.h>
28 int main (int argc, char** argv)
30 notmuch_database_t *db;
32 notmuch_status_t stat;
35 for (int i = 1; i < argc; i++)
36 if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
38 stat = notmuch_database_open_with_config (argv[1],
39 NOTMUCH_DATABASE_MODE_READ_WRITE,
44 if (stat != NOTMUCH_STATUS_SUCCESS) {
45 fprintf (stderr, "error opening database\n%s\n%s\n", notmuch_status_to_string (stat), msg ? msg : "");
51 EXPECT0(notmuch_database_destroy(db));
55 test_begin_subtest "notmuch_database_{set,get}_config"
56 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG}
58 EXPECT0(notmuch_database_set_config (db, "test.key1", "testvalue1"));
59 EXPECT0(notmuch_database_set_config (db, "test.key2", "testvalue2"));
60 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
61 printf("test.key1 = %s\n", val);
62 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
63 printf("test.key2 = %s\n", val);
68 test.key1 = testvalue1
69 test.key2 = testvalue2
72 test_expect_equal_file EXPECTED OUTPUT
75 test_begin_subtest "notmuch_database_get_config_list: empty list"
76 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
78 notmuch_config_list_t *list;
79 EXPECT0(notmuch_database_get_config_list (db, "nonexistent", &list));
80 printf("valid = %d\n", notmuch_config_list_valid (list));
81 notmuch_config_list_destroy (list);
89 test_expect_equal_file EXPECTED OUTPUT
91 test_begin_subtest "notmuch_database_get_config_list: closed db"
92 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
94 notmuch_config_list_t *list;
95 EXPECT0(notmuch_database_close (db));
96 stat = notmuch_database_get_config_list (db, "nonexistent", &list);
97 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
100 cat <<'EOF' >EXPECTED
105 test_expect_equal_file EXPECTED OUTPUT
107 test_begin_subtest "notmuch_database_get_config_list: all pairs"
108 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
110 notmuch_config_list_t *list;
111 EXPECT0(notmuch_database_set_config (db, "zzzafter", "afterval"));
112 EXPECT0(notmuch_database_set_config (db, "aaabefore", "beforeval"));
113 EXPECT0(notmuch_database_get_config_list (db, "", &list));
114 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
115 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
117 notmuch_config_list_destroy (list);
120 cat <<'EOF' >EXPECTED
128 test_expect_equal_file EXPECTED OUTPUT
130 test_begin_subtest "notmuch_database_get_config_list: all pairs (closed db)"
131 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
133 notmuch_config_list_t *list;
134 EXPECT0(notmuch_database_get_config_list (db, "", &list));
135 EXPECT0(notmuch_database_close (db));
136 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
137 printf("%s %d\n", notmuch_config_list_key (list), NULL == notmuch_config_list_value(list));
139 notmuch_config_list_destroy (list);
142 cat <<'EOF' >EXPECTED
150 test_expect_equal_file EXPECTED OUTPUT
152 test_begin_subtest "notmuch_database_get_config_list: one prefix"
153 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
155 notmuch_config_list_t *list;
156 EXPECT0(notmuch_database_get_config_list (db, "test.key", &list));
157 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
158 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
160 notmuch_config_list_destroy (list);
163 cat <<'EOF' >EXPECTED
169 test_expect_equal_file EXPECTED OUTPUT
171 test_begin_subtest "dump config"
172 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
174 EXPECT0(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));
177 notmuch dump --include=config >OUTPUT
178 cat <<'EOF' >EXPECTED
179 #notmuch-dump batch-tag:3 config
180 #@ aaabefore beforeval
181 #@ key%20with%20spaces value,%20with,%20spaces%21
182 #@ test.key1 testvalue1
183 #@ test.key2 testvalue2
186 test_expect_equal_file EXPECTED OUTPUT
188 test_begin_subtest "restore config"
189 notmuch dump --include=config >EXPECTED
190 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
192 EXPECT0(notmuch_database_set_config (db, "test.key1", "mutatedvalue"));
195 notmuch restore --include=config <EXPECTED
196 notmuch dump --include=config >OUTPUT
197 test_expect_equal_file EXPECTED OUTPUT
200 test_begin_subtest "override config from file"
201 notmuch config set test.key1 overridden
202 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG}
204 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
205 printf("test.key1 = %s\n", val);
206 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
207 printf("test.key2 = %s\n", val);
210 cat <<'EOF' >EXPECTED
212 test.key1 = overridden
213 test.key2 = testvalue2
216 test_expect_equal_file EXPECTED OUTPUT
219 test_begin_subtest "NOTMUCH_CONFIG_HOOK_DIR: traditional"
220 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
222 const char *val = notmuch_config_get (db, NOTMUCH_CONFIG_HOOK_DIR);
223 printf("database.hook_dir = %s\n", val);
226 cat <<'EOF' >EXPECTED
228 database.hook_dir = MAIL_DIR/.notmuch/hooks
231 test_expect_equal_file EXPECTED OUTPUT
233 test_begin_subtest "NOTMUCH_CONFIG_HOOK_DIR: xdg"
234 dir="${HOME}/.config/notmuch/default/hooks"
236 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
238 const char *val = notmuch_config_get (db, NOTMUCH_CONFIG_HOOK_DIR);
239 printf("database.hook_dir = %s\n", val);
242 cat <<'EOF' >EXPECTED
244 database.hook_dir = CWD/home/.config/notmuch/default/hooks
248 test_expect_equal_file EXPECTED OUTPUT
250 test_begin_subtest "notmuch_config_get_values"
251 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
253 notmuch_config_values_t *values;
254 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, "a;b;c"));
255 for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS);
256 notmuch_config_values_valid (values);
257 notmuch_config_values_move_to_next (values))
259 puts (notmuch_config_values_get (values));
263 cat <<'EOF' >EXPECTED
270 test_expect_equal_file EXPECTED OUTPUT
273 test_begin_subtest "notmuch_config_get_values (ignore leading/trailing whitespace)"
274 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
276 notmuch_config_values_t *values;
277 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, " a ; b c ; d "));
278 for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS);
279 notmuch_config_values_valid (values);
280 notmuch_config_values_move_to_next (values))
282 puts (notmuch_config_values_get (values));
286 cat <<'EOF' >EXPECTED
293 test_expect_equal_file EXPECTED OUTPUT
296 test_begin_subtest "notmuch_config_get_values_string"
297 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
299 notmuch_config_values_t *values;
300 EXPECT0(notmuch_database_set_config (db, "test.list", "x;y;z"));
301 for (values = notmuch_config_get_values_string (db, "test.list");
302 notmuch_config_values_valid (values);
303 notmuch_config_values_move_to_next (values))
305 puts (notmuch_config_values_get (values));
309 cat <<'EOF' >EXPECTED
316 test_expect_equal_file EXPECTED OUTPUT
319 test_begin_subtest "notmuch_config_get_values (restart)"
320 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
322 notmuch_config_values_t *values;
323 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, "a;b;c"));
324 for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS);
325 notmuch_config_values_valid (values);
326 notmuch_config_values_move_to_next (values))
328 puts (notmuch_config_values_get (values));
330 for (notmuch_config_values_start (values);
331 notmuch_config_values_valid (values);
332 notmuch_config_values_move_to_next (values))
334 puts (notmuch_config_values_get (values));
338 cat <<'EOF' >EXPECTED
348 test_expect_equal_file EXPECTED OUTPUT
352 test_begin_subtest "notmuch_config_get_values, trailing ;"
353 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
355 notmuch_config_values_t *values;
356 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, "a;b;c"));
357 for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS);
358 notmuch_config_values_valid (values);
359 notmuch_config_values_move_to_next (values))
361 puts (notmuch_config_values_get (values));
365 cat <<'EOF' >EXPECTED
372 test_expect_equal_file EXPECTED OUTPUT
376 test_begin_subtest "get config by key"
377 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG}
379 printf("before = %s\n", notmuch_config_get (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS));
380 EXPECT0(notmuch_database_set_config (db, "maildir.synchronize_flags", "false"));
381 printf("after = %s\n", notmuch_config_get (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS));
384 cat <<'EOF' >EXPECTED
390 test_expect_equal_file EXPECTED OUTPUT
394 test_begin_subtest "set config by key"
395 notmuch config set test.key1 overridden
396 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG}
398 printf("before = %s\n", notmuch_config_get (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS));
399 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS, "false"));
400 printf("after = %s\n", notmuch_config_get (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS));
403 cat <<'EOF' >EXPECTED
409 test_expect_equal_file EXPECTED OUTPUT
412 test_begin_subtest "load default values"
413 export MAILDIR=${MAIL_DIR}
414 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} '' %NULL%
416 notmuch_config_key_t key;
417 for (key = NOTMUCH_CONFIG_FIRST;
418 key < NOTMUCH_CONFIG_LAST;
419 key = (notmuch_config_key_t)(key + 1)) {
420 const char *val = notmuch_config_get (db, key);
421 printf("%02d: '%s'\n", key, val ? val : "NULL" );
426 _libconfig_sanitize < OUTPUT > OUTPUT.clean
428 cat <<'EOF' >EXPECTED
432 02: 'MAIL_DIR/.notmuch/hooks'
433 03: 'MAIL_DIR/.notmuch/backups'
438 08: 'USERNAME@localhost'
447 test_expect_equal_file EXPECTED OUTPUT.clean
450 test_begin_subtest "override config from \${NOTMUCH_CONFIG}"
451 notmuch config set test.key1 overridden
452 # second argument omitted to make argv[2] == NULL
453 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
455 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
456 printf("test.key1 = %s\n", val);
457 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
458 printf("test.key2 = %s\n", val);
461 notmuch config set test.key1
462 cat <<'EOF' >EXPECTED
464 test.key1 = overridden
465 test.key2 = testvalue2
468 test_expect_equal_file EXPECTED OUTPUT
472 test_begin_subtest "override config from \${HOME}/.notmuch-config"
473 ovconfig=${HOME}/.notmuch-config
474 cp ${NOTMUCH_CONFIG} ${ovconfig}
475 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
477 notmuch --config=${ovconfig} config set test.key1 overridden-home
478 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
480 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
481 printf("test.key1 = %s\n", val);
482 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
483 printf("test.key2 = %s\n", val);
487 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
488 cat <<'EOF' >EXPECTED
490 test.key1 = overridden-home
491 test.key2 = testvalue2
494 test_expect_equal_file EXPECTED OUTPUT
498 test_begin_subtest "override config from \${XDG_CONFIG_HOME}/notmuch"
499 ovconfig=${HOME}/.config/notmuch/default/config
500 mkdir -p $(dirname ${ovconfig})
501 cp ${NOTMUCH_CONFIG} ${ovconfig}
502 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
504 notmuch --config=${ovconfig} config set test.key1 overridden-xdg
505 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
507 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
508 printf("test.key1 = %s\n", val);
509 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
510 printf("test.key2 = %s\n", val);
514 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
515 cat <<'EOF' >EXPECTED
517 test.key1 = overridden-xdg
518 test.key2 = testvalue2
521 test_expect_equal_file EXPECTED OUTPUT
525 test_begin_subtest "override config from \${XDG_CONFIG_HOME}/notmuch with profile"
526 ovconfig=${HOME}/.config/notmuch/work/config
527 mkdir -p $(dirname ${ovconfig})
528 cp ${NOTMUCH_CONFIG} ${ovconfig}
529 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
531 notmuch --config=${ovconfig} config set test.key1 overridden-xdg-profile
532 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% work
534 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
535 printf("test.key1 = %s\n", val);
536 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
537 printf("test.key2 = %s\n", val);
541 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
542 cat <<'EOF' >EXPECTED
544 test.key1 = overridden-xdg-profile
545 test.key2 = testvalue2
548 test_expect_equal_file EXPECTED OUTPUT
552 test_begin_subtest "override config from \${HOME}/.notmuch-config.work (via args)"
553 ovconfig=${HOME}/.notmuch-config.work
554 cp ${NOTMUCH_CONFIG} ${ovconfig}
555 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
557 notmuch --config=${ovconfig} config set test.key1 overridden-profile
558 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% work
560 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
561 printf("test.key1 = %s\n", val);
562 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
563 printf("test.key2 = %s\n", val);
567 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
568 cat <<'EOF' >EXPECTED
570 test.key1 = overridden-profile
571 test.key2 = testvalue2
574 test_expect_equal_file EXPECTED OUTPUT
577 test_begin_subtest "no config, fail to open database"
578 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
580 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
585 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
586 cat <<'EOF' >EXPECTED
589 error opening database
591 Error: could not locate database.
594 test_expect_equal_file EXPECTED OUTPUT
596 test_begin_subtest "open database from NOTMUCH_DATABASE"
597 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
599 export NOTMUCH_DATABASE=${MAIL_DIR}
600 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
602 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
603 printf("test.key1 = %s\n", val);
604 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
605 printf("test.key2 = %s\n", val);
608 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
609 unset NOTMUCH_DATABASE
610 cat <<'EOF' >EXPECTED
612 test.key1 = testvalue1
613 test.key2 = testvalue2
616 test_expect_equal_file EXPECTED OUTPUT
618 test_begin_subtest "NOTMUCH_DATABASE overrides config"
619 cp notmuch-config notmuch-config.bak
620 notmuch config set database.path /nonexistent
621 export NOTMUCH_DATABASE=${MAIL_DIR}
622 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
624 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
625 printf("test.key1 = %s\n", val);
626 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
627 printf("test.key2 = %s\n", val);
630 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
631 unset NOTMUCH_DATABASE
632 cat <<'EOF' >EXPECTED
634 test.key1 = testvalue1
635 test.key2 = testvalue2
638 cp notmuch-config.bak notmuch-config
639 test_expect_equal_file EXPECTED OUTPUT
642 #include <notmuch-test.h>
644 int main (int argc, char** argv)
646 notmuch_database_t *db;
648 notmuch_status_t stat;
651 for (int i = 1; i < argc; i++)
652 if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
654 stat = notmuch_database_load_config (argv[1],
659 if (stat != NOTMUCH_STATUS_SUCCESS && stat != NOTMUCH_STATUS_NO_CONFIG) {
660 fprintf (stderr, "error opening database\n%d: %s\n%s\n", stat,
661 notmuch_status_to_string (stat), msg ? msg : "");
667 test_begin_subtest "notmuch_database_get_config (ndlc)"
668 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
670 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
671 printf("test.key1 = %s\n", val);
672 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
673 printf("test.key2 = %s\n", val);
676 cat <<'EOF' >EXPECTED
678 test.key1 = testvalue1
679 test.key2 = testvalue2
682 test_expect_equal_file EXPECTED OUTPUT
685 test_begin_subtest "notmuch_database_get_config_list: all pairs (ndlc)"
686 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
688 notmuch_config_list_t *list;
689 EXPECT0(notmuch_database_get_config_list (db, "", &list));
690 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
691 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
693 notmuch_config_list_destroy (list);
696 cat <<'EOF' >EXPECTED
699 key with spaces value, with, spaces!
705 test_expect_equal_file EXPECTED OUTPUT
707 test_begin_subtest "notmuch_database_get_config_list: one prefix (ndlc)"
708 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
710 notmuch_config_list_t *list;
711 EXPECT0(notmuch_database_get_config_list (db, "test.key", &list));
712 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
713 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
715 notmuch_config_list_destroy (list);
718 cat <<'EOF' >EXPECTED
724 test_expect_equal_file EXPECTED OUTPUT
726 test_begin_subtest "list by keys (ndlc)"
727 notmuch config set search.exclude_tags "foo;bar;fub"
728 notmuch config set new.ignore "sekrit_junk"
729 notmuch config set index.as_text "text/"
730 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
732 notmuch_config_key_t key;
733 for (key = NOTMUCH_CONFIG_FIRST;
734 key < NOTMUCH_CONFIG_LAST;
735 key = (notmuch_config_key_t)(key + 1)) {
736 const char *val = notmuch_config_get (db, key);
737 printf("%02d: '%s'\n", key, val ? val : "NULL" );
741 cat <<'EOF' >EXPECTED
745 02: 'MAIL_DIR/.notmuch/hooks'
746 03: 'MAIL_DIR/.notmuch/backups'
751 08: 'test_suite@notmuchmail.org'
752 09: 'test_suite_other@notmuchmail.org;test_suite@otherdomain.org'
753 10: 'Notmuch Test Suite'
759 test_expect_equal_file EXPECTED OUTPUT
761 test_begin_subtest "load default values (ndlc, nonexistent config)"
762 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} /nonexistent %NULL%
764 notmuch_config_key_t key;
765 for (key = NOTMUCH_CONFIG_FIRST;
766 key < NOTMUCH_CONFIG_LAST;
767 key = (notmuch_config_key_t)(key + 1)) {
768 const char *val = notmuch_config_get (db, key);
769 printf("%02d: '%s'\n", key, val ? val : "NULL" );
774 _libconfig_sanitize < OUTPUT > OUTPUT.clean
776 cat <<'EOF' >EXPECTED
780 02: 'MAIL_DIR/.notmuch/hooks'
781 03: 'MAIL_DIR/.notmuch/backups'
786 08: 'USERNAME@localhost'
794 test_expect_equal_file EXPECTED OUTPUT.clean
797 test_begin_subtest "override config from \${HOME}/.notmuch-config (ndlc)"
798 ovconfig=${HOME}/.notmuch-config
799 cp ${NOTMUCH_CONFIG} ${ovconfig}
800 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
802 notmuch --config=${ovconfig} config set test.key1 overridden-home
803 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
805 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
806 printf("test.key1 = %s\n", val);
807 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
808 printf("test.key2 = %s\n", val);
812 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
813 cat <<'EOF' >EXPECTED
815 test.key1 = overridden-home
816 test.key2 = testvalue2
819 test_expect_equal_file EXPECTED OUTPUT
822 test_begin_subtest "notmuch_config_get_pairs: prefix (ndlc)"
823 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
825 notmuch_config_pairs_t *list;
826 for (list = notmuch_config_get_pairs (db, "user.");
827 notmuch_config_pairs_valid (list);
828 notmuch_config_pairs_move_to_next (list)) {
829 printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list));
831 notmuch_config_pairs_destroy (list);
834 cat <<'EOF' >EXPECTED
836 user.name Notmuch Test Suite
837 user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org
838 user.primary_email test_suite@notmuchmail.org
841 test_expect_equal_file EXPECTED OUTPUT
843 test_begin_subtest "notmuch_config_get_pairs: all pairs (ndlc)"
844 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
846 notmuch_config_pairs_t *list;
847 for (list = notmuch_config_get_pairs (db, "");
848 notmuch_config_pairs_valid (list);
849 notmuch_config_pairs_move_to_next (list)) {
850 printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list));
852 notmuch_config_pairs_destroy (list);
855 cat <<'EOF' >EXPECTED
858 database.autocommit 8000
859 database.backup_dir MAIL_DIR/.notmuch/backups
860 database.hook_dir MAIL_DIR/.notmuch/hooks
861 database.mail_root MAIL_DIR
862 database.path MAIL_DIR
864 key with spaces value, with, spaces!
865 maildir.synchronize_flags true
866 new.ignore sekrit_junk
867 new.tags unread;inbox
868 search.exclude_tags foo;bar;fub
869 show.extra_headers (null)
872 user.name Notmuch Test Suite
873 user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org
874 user.primary_email test_suite@notmuchmail.org
878 test_expect_equal_file EXPECTED OUTPUT
881 #include <notmuch-test.h>
882 int main (int argc, char **argv) {
883 notmuch_status_t stat;
884 notmuch_database_t *db = NULL;
888 printf("db == NULL: %d\n", db == NULL);
892 test_begin_subtest "open: database set to null on missing config"
893 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
894 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
895 NOTMUCH_DATABASE_MODE_READ_ONLY,
896 "/nonexistent", NULL, &db, NULL);
903 test_expect_equal_file EXPECTED OUTPUT
905 test_begin_subtest "open: database set to null on missing config (env)"
906 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
907 export NOTMUCH_CONFIG="/nonexistent"
908 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
909 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
910 NOTMUCH_DATABASE_MODE_READ_ONLY,
911 NULL, NULL, &db, NULL);
913 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
919 test_expect_equal_file EXPECTED OUTPUT
921 test_begin_subtest "create: database set to null on missing config"
922 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent"
923 notmuch_status_t st = notmuch_database_create_with_config(argv[1],argv[2], NULL, &db, NULL);
930 test_expect_equal_file EXPECTED OUTPUT
932 test_begin_subtest "create: database set to null on missing config (env)"
933 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
934 export NOTMUCH_CONFIG="/nonexistent"
935 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
936 notmuch_status_t st = notmuch_database_create_with_config(argv[1],
937 NULL, NULL, &db, NULL);
939 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
945 test_expect_equal_file EXPECTED OUTPUT
947 test_begin_subtest "load_config: database set non-null on missing config"
948 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent"
949 notmuch_status_t st = notmuch_database_load_config(argv[1],argv[2], NULL, &db, NULL);
956 test_expect_equal_file EXPECTED OUTPUT
958 test_begin_subtest "load_config: database non-null on missing config (env)"
959 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
960 export NOTMUCH_CONFIG="/nonexistent"
961 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
962 notmuch_status_t st = notmuch_database_load_config(argv[1], NULL, NULL, &db, NULL);
964 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
970 test_expect_equal_file EXPECTED OUTPUT
972 test_begin_subtest "load_config: database set to NULL on fatal error"
973 cat c_head3 - c_tail3 <<'EOF' | test_C
974 notmuch_status_t st = notmuch_database_load_config("relative", NULL, NULL, &db, NULL);
981 test_expect_equal_file EXPECTED OUTPUT
983 test_begin_subtest "open: database parameter overrides implicit config"
984 cp $NOTMUCH_CONFIG ${NOTMUCH_CONFIG}.bak
985 notmuch config set database.path ${MAIL_DIR}/nonexistent
986 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
987 const char *path = NULL;
988 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
989 NOTMUCH_DATABASE_MODE_READ_ONLY,
990 NULL, NULL, &db, NULL);
991 printf ("status: %d\n", st);
992 path = notmuch_database_get_path (db);
993 printf ("path: %s\n", path ? path : "(null)");
995 cp ${NOTMUCH_CONFIG}.bak ${NOTMUCH_CONFIG}
1003 notmuch_dir_sanitize < OUTPUT > OUTPUT.clean
1004 test_expect_equal_file EXPECTED OUTPUT.clean
1007 notmuch_status_t st = notmuch_database_open_with_config(NULL,
1008 NOTMUCH_DATABASE_MODE_READ_ONLY,
1009 "", NULL, &db, NULL);
1010 printf ("status == SUCCESS: %d\n", st == NOTMUCH_STATUS_SUCCESS);
1012 const char *mail_root = NULL;
1013 mail_root = notmuch_config_get (db, NOTMUCH_CONFIG_MAIL_ROOT);
1014 printf ("mail_root: %s\n", mail_root ? mail_root : "(null)");
1018 cat <<EOF> EXPECTED.common
1020 status == SUCCESS: 0
1025 test_begin_subtest "open/error: config=empty with no mail root in db "
1026 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
1027 unset NOTMUCH_CONFIG
1028 cat c_head3 c_body c_tail3 | test_C
1029 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
1030 notmuch_dir_sanitize < OUTPUT > OUTPUT.clean
1031 test_expect_equal_file EXPECTED.common OUTPUT.clean
1033 test_begin_subtest "open/error: config=empty with no mail root in db (xdg)"
1034 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
1035 unset NOTMUCH_CONFIG
1037 mkdir -p home/.local/share/notmuch
1038 mv mail/.notmuch home/.local/share/notmuch/default
1039 cat c_head3 c_body c_tail3 | test_C
1041 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
1042 notmuch_dir_sanitize < OUTPUT > OUTPUT.clean
1043 test_expect_equal_file EXPECTED.common OUTPUT.clean