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'
445 test_expect_equal_file EXPECTED OUTPUT.clean
448 test_begin_subtest "override config from \${NOTMUCH_CONFIG}"
449 notmuch config set test.key1 overridden
450 # second argument omitted to make argv[2] == NULL
451 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
453 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
454 printf("test.key1 = %s\n", val);
455 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
456 printf("test.key2 = %s\n", val);
459 notmuch config set test.key1
460 cat <<'EOF' >EXPECTED
462 test.key1 = overridden
463 test.key2 = testvalue2
466 test_expect_equal_file EXPECTED OUTPUT
470 test_begin_subtest "override config from \${HOME}/.notmuch-config"
471 ovconfig=${HOME}/.notmuch-config
472 cp ${NOTMUCH_CONFIG} ${ovconfig}
473 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
475 notmuch --config=${ovconfig} config set test.key1 overridden-home
476 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
478 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
479 printf("test.key1 = %s\n", val);
480 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
481 printf("test.key2 = %s\n", val);
485 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
486 cat <<'EOF' >EXPECTED
488 test.key1 = overridden-home
489 test.key2 = testvalue2
492 test_expect_equal_file EXPECTED OUTPUT
496 test_begin_subtest "override config from \${XDG_CONFIG_HOME}/notmuch"
497 ovconfig=${HOME}/.config/notmuch/default/config
498 mkdir -p $(dirname ${ovconfig})
499 cp ${NOTMUCH_CONFIG} ${ovconfig}
500 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
502 notmuch --config=${ovconfig} config set test.key1 overridden-xdg
503 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
505 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
506 printf("test.key1 = %s\n", val);
507 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
508 printf("test.key2 = %s\n", val);
512 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
513 cat <<'EOF' >EXPECTED
515 test.key1 = overridden-xdg
516 test.key2 = testvalue2
519 test_expect_equal_file EXPECTED OUTPUT
523 test_begin_subtest "override config from \${XDG_CONFIG_HOME}/notmuch with profile"
524 ovconfig=${HOME}/.config/notmuch/work/config
525 mkdir -p $(dirname ${ovconfig})
526 cp ${NOTMUCH_CONFIG} ${ovconfig}
527 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
529 notmuch --config=${ovconfig} config set test.key1 overridden-xdg-profile
530 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% work
532 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
533 printf("test.key1 = %s\n", val);
534 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
535 printf("test.key2 = %s\n", val);
539 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
540 cat <<'EOF' >EXPECTED
542 test.key1 = overridden-xdg-profile
543 test.key2 = testvalue2
546 test_expect_equal_file EXPECTED OUTPUT
550 test_begin_subtest "override config from \${HOME}/.notmuch-config.work (via args)"
551 ovconfig=${HOME}/.notmuch-config.work
552 cp ${NOTMUCH_CONFIG} ${ovconfig}
553 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
555 notmuch --config=${ovconfig} config set test.key1 overridden-profile
556 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% work
558 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
559 printf("test.key1 = %s\n", val);
560 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
561 printf("test.key2 = %s\n", val);
565 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
566 cat <<'EOF' >EXPECTED
568 test.key1 = overridden-profile
569 test.key2 = testvalue2
572 test_expect_equal_file EXPECTED OUTPUT
575 test_begin_subtest "no config, fail to open database"
576 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
578 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
583 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
584 cat <<'EOF' >EXPECTED
587 error opening database
589 Error: could not locate database.
592 test_expect_equal_file EXPECTED OUTPUT
594 test_begin_subtest "open database from NOTMUCH_DATABASE"
595 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
597 export NOTMUCH_DATABASE=${MAIL_DIR}
598 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
600 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
601 printf("test.key1 = %s\n", val);
602 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
603 printf("test.key2 = %s\n", val);
606 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
607 unset NOTMUCH_DATABASE
608 cat <<'EOF' >EXPECTED
610 test.key1 = testvalue1
611 test.key2 = testvalue2
614 test_expect_equal_file EXPECTED OUTPUT
616 test_begin_subtest "NOTMUCH_DATABASE overrides config"
617 cp notmuch-config notmuch-config.bak
618 notmuch config set database.path /nonexistent
619 export NOTMUCH_DATABASE=${MAIL_DIR}
620 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
622 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
623 printf("test.key1 = %s\n", val);
624 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
625 printf("test.key2 = %s\n", val);
628 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
629 unset NOTMUCH_DATABASE
630 cat <<'EOF' >EXPECTED
632 test.key1 = testvalue1
633 test.key2 = testvalue2
636 cp notmuch-config.bak notmuch-config
637 test_expect_equal_file EXPECTED OUTPUT
640 #include <notmuch-test.h>
642 int main (int argc, char** argv)
644 notmuch_database_t *db;
646 notmuch_status_t stat;
649 for (int i = 1; i < argc; i++)
650 if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
652 stat = notmuch_database_load_config (argv[1],
657 if (stat != NOTMUCH_STATUS_SUCCESS && stat != NOTMUCH_STATUS_NO_CONFIG) {
658 fprintf (stderr, "error opening database\n%d: %s\n%s\n", stat,
659 notmuch_status_to_string (stat), msg ? msg : "");
665 test_begin_subtest "notmuch_database_get_config (ndlc)"
666 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
668 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
669 printf("test.key1 = %s\n", val);
670 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
671 printf("test.key2 = %s\n", val);
674 cat <<'EOF' >EXPECTED
676 test.key1 = testvalue1
677 test.key2 = testvalue2
680 test_expect_equal_file EXPECTED OUTPUT
683 test_begin_subtest "notmuch_database_get_config_list: all pairs (ndlc)"
684 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
686 notmuch_config_list_t *list;
687 EXPECT0(notmuch_database_get_config_list (db, "", &list));
688 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
689 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
691 notmuch_config_list_destroy (list);
694 cat <<'EOF' >EXPECTED
697 key with spaces value, with, spaces!
703 test_expect_equal_file EXPECTED OUTPUT
705 test_begin_subtest "notmuch_database_get_config_list: one prefix (ndlc)"
706 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
708 notmuch_config_list_t *list;
709 EXPECT0(notmuch_database_get_config_list (db, "test.key", &list));
710 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
711 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
713 notmuch_config_list_destroy (list);
716 cat <<'EOF' >EXPECTED
722 test_expect_equal_file EXPECTED OUTPUT
724 test_begin_subtest "list by keys (ndlc)"
725 notmuch config set search.exclude_tags "foo;bar;fub"
726 notmuch config set new.ignore "sekrit_junk"
727 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
729 notmuch_config_key_t key;
730 for (key = NOTMUCH_CONFIG_FIRST;
731 key < NOTMUCH_CONFIG_LAST;
732 key = (notmuch_config_key_t)(key + 1)) {
733 const char *val = notmuch_config_get (db, key);
734 printf("%02d: '%s'\n", key, val ? val : "NULL" );
738 cat <<'EOF' >EXPECTED
742 02: 'MAIL_DIR/.notmuch/hooks'
743 03: 'MAIL_DIR/.notmuch/backups'
748 08: 'test_suite@notmuchmail.org'
749 09: 'test_suite_other@notmuchmail.org;test_suite@otherdomain.org'
750 10: 'Notmuch Test Suite'
754 test_expect_equal_file EXPECTED OUTPUT
756 test_begin_subtest "load default values (ndlc, nonexistent config)"
757 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} /nonexistent %NULL%
759 notmuch_config_key_t key;
760 for (key = NOTMUCH_CONFIG_FIRST;
761 key < NOTMUCH_CONFIG_LAST;
762 key = (notmuch_config_key_t)(key + 1)) {
763 const char *val = notmuch_config_get (db, key);
764 printf("%02d: '%s'\n", key, val ? val : "NULL" );
769 _libconfig_sanitize < OUTPUT > OUTPUT.clean
771 cat <<'EOF' >EXPECTED
775 02: 'MAIL_DIR/.notmuch/hooks'
776 03: 'MAIL_DIR/.notmuch/backups'
781 08: 'USERNAME@localhost'
787 test_expect_equal_file EXPECTED OUTPUT.clean
790 test_begin_subtest "override config from \${HOME}/.notmuch-config (ndlc)"
791 ovconfig=${HOME}/.notmuch-config
792 cp ${NOTMUCH_CONFIG} ${ovconfig}
793 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
795 notmuch --config=${ovconfig} config set test.key1 overridden-home
796 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
798 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
799 printf("test.key1 = %s\n", val);
800 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
801 printf("test.key2 = %s\n", val);
805 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
806 cat <<'EOF' >EXPECTED
808 test.key1 = overridden-home
809 test.key2 = testvalue2
812 test_expect_equal_file EXPECTED OUTPUT
815 test_begin_subtest "notmuch_config_get_pairs: prefix (ndlc)"
816 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
818 notmuch_config_pairs_t *list;
819 for (list = notmuch_config_get_pairs (db, "user.");
820 notmuch_config_pairs_valid (list);
821 notmuch_config_pairs_move_to_next (list)) {
822 printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list));
824 notmuch_config_pairs_destroy (list);
827 cat <<'EOF' >EXPECTED
829 user.name Notmuch Test Suite
830 user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org
831 user.primary_email test_suite@notmuchmail.org
834 test_expect_equal_file EXPECTED OUTPUT
836 test_begin_subtest "notmuch_config_get_pairs: all pairs (ndlc)"
837 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
839 notmuch_config_pairs_t *list;
840 for (list = notmuch_config_get_pairs (db, "");
841 notmuch_config_pairs_valid (list);
842 notmuch_config_pairs_move_to_next (list)) {
843 printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list));
845 notmuch_config_pairs_destroy (list);
848 cat <<'EOF' >EXPECTED
851 database.autocommit 8000
852 database.backup_dir MAIL_DIR/.notmuch/backups
853 database.hook_dir MAIL_DIR/.notmuch/hooks
854 database.mail_root MAIL_DIR
855 database.path MAIL_DIR
856 key with spaces value, with, spaces!
857 maildir.synchronize_flags true
858 new.ignore sekrit_junk
859 new.tags unread;inbox
860 search.exclude_tags foo;bar;fub
863 user.name Notmuch Test Suite
864 user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org
865 user.primary_email test_suite@notmuchmail.org
869 test_expect_equal_file EXPECTED OUTPUT
872 #include <notmuch-test.h>
873 int main (int argc, char **argv) {
874 notmuch_status_t stat;
875 notmuch_database_t *db = NULL;
879 printf("db == NULL: %d\n", db == NULL);
883 test_begin_subtest "open: database set to null on missing config"
884 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
885 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
886 NOTMUCH_DATABASE_MODE_READ_ONLY,
887 "/nonexistent", NULL, &db, NULL);
894 test_expect_equal_file EXPECTED OUTPUT
896 test_begin_subtest "open: database set to null on missing config (env)"
897 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
898 export NOTMUCH_CONFIG="/nonexistent"
899 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
900 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
901 NOTMUCH_DATABASE_MODE_READ_ONLY,
902 NULL, NULL, &db, NULL);
904 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
910 test_expect_equal_file EXPECTED OUTPUT
912 test_begin_subtest "create: database set to null on missing config"
913 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent"
914 notmuch_status_t st = notmuch_database_create_with_config(argv[1],argv[2], NULL, &db, NULL);
921 test_expect_equal_file EXPECTED OUTPUT
923 test_begin_subtest "create: database set to null on missing config (env)"
924 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
925 export NOTMUCH_CONFIG="/nonexistent"
926 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
927 notmuch_status_t st = notmuch_database_create_with_config(argv[1],
928 NULL, NULL, &db, NULL);
930 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
936 test_expect_equal_file EXPECTED OUTPUT
938 test_begin_subtest "load_config: database set non-null on missing config"
939 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent"
940 notmuch_status_t st = notmuch_database_load_config(argv[1],argv[2], NULL, &db, NULL);
947 test_expect_equal_file EXPECTED OUTPUT
949 test_begin_subtest "load_config: database non-null on missing config (env)"
950 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
951 export NOTMUCH_CONFIG="/nonexistent"
952 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
953 notmuch_status_t st = notmuch_database_load_config(argv[1], NULL, NULL, &db, NULL);
955 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
961 test_expect_equal_file EXPECTED OUTPUT
963 test_begin_subtest "load_config: database set to NULL on fatal error"
964 cat c_head3 - c_tail3 <<'EOF' | test_C
965 notmuch_status_t st = notmuch_database_load_config("relative", NULL, NULL, &db, NULL);
972 test_expect_equal_file EXPECTED OUTPUT
974 test_begin_subtest "open: database parameter overrides implicit config"
975 notmuch config set database.path ${MAIL_DIR}/nonexistent
976 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
977 const char *path = NULL;
978 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
979 NOTMUCH_DATABASE_MODE_READ_ONLY,
980 NULL, NULL, &db, NULL);
981 printf ("status: %d\n", st);
982 path = notmuch_database_get_path (db);
983 printf ("path: %s\n", path ? path : "(null)");
992 notmuch_dir_sanitize < OUTPUT > OUTPUT.clean
993 test_expect_equal_file EXPECTED OUTPUT.clean