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'
446 test_expect_equal_file EXPECTED OUTPUT.clean
449 test_begin_subtest "override config from \${NOTMUCH_CONFIG}"
450 notmuch config set test.key1 overridden
451 # second argument omitted to make argv[2] == NULL
452 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
454 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
455 printf("test.key1 = %s\n", val);
456 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
457 printf("test.key2 = %s\n", val);
460 notmuch config set test.key1
461 cat <<'EOF' >EXPECTED
463 test.key1 = overridden
464 test.key2 = testvalue2
467 test_expect_equal_file EXPECTED OUTPUT
471 test_begin_subtest "override config from \${HOME}/.notmuch-config"
472 ovconfig=${HOME}/.notmuch-config
473 cp ${NOTMUCH_CONFIG} ${ovconfig}
474 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
476 notmuch --config=${ovconfig} config set test.key1 overridden-home
477 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
479 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
480 printf("test.key1 = %s\n", val);
481 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
482 printf("test.key2 = %s\n", val);
486 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
487 cat <<'EOF' >EXPECTED
489 test.key1 = overridden-home
490 test.key2 = testvalue2
493 test_expect_equal_file EXPECTED OUTPUT
497 test_begin_subtest "override config from \${XDG_CONFIG_HOME}/notmuch"
498 ovconfig=${HOME}/.config/notmuch/default/config
499 mkdir -p $(dirname ${ovconfig})
500 cp ${NOTMUCH_CONFIG} ${ovconfig}
501 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
503 notmuch --config=${ovconfig} config set test.key1 overridden-xdg
504 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
506 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
507 printf("test.key1 = %s\n", val);
508 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
509 printf("test.key2 = %s\n", val);
513 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
514 cat <<'EOF' >EXPECTED
516 test.key1 = overridden-xdg
517 test.key2 = testvalue2
520 test_expect_equal_file EXPECTED OUTPUT
524 test_begin_subtest "override config from \${XDG_CONFIG_HOME}/notmuch with profile"
525 ovconfig=${HOME}/.config/notmuch/work/config
526 mkdir -p $(dirname ${ovconfig})
527 cp ${NOTMUCH_CONFIG} ${ovconfig}
528 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
530 notmuch --config=${ovconfig} config set test.key1 overridden-xdg-profile
531 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% work
533 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
534 printf("test.key1 = %s\n", val);
535 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
536 printf("test.key2 = %s\n", val);
540 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
541 cat <<'EOF' >EXPECTED
543 test.key1 = overridden-xdg-profile
544 test.key2 = testvalue2
547 test_expect_equal_file EXPECTED OUTPUT
551 test_begin_subtest "override config from \${HOME}/.notmuch-config.work (via args)"
552 ovconfig=${HOME}/.notmuch-config.work
553 cp ${NOTMUCH_CONFIG} ${ovconfig}
554 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
556 notmuch --config=${ovconfig} config set test.key1 overridden-profile
557 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% work
559 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
560 printf("test.key1 = %s\n", val);
561 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
562 printf("test.key2 = %s\n", val);
566 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
567 cat <<'EOF' >EXPECTED
569 test.key1 = overridden-profile
570 test.key2 = testvalue2
573 test_expect_equal_file EXPECTED OUTPUT
576 test_begin_subtest "no config, fail to open database"
577 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
579 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
584 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
585 cat <<'EOF' >EXPECTED
588 error opening database
590 Error: could not locate database.
593 test_expect_equal_file EXPECTED OUTPUT
595 test_begin_subtest "open database from NOTMUCH_DATABASE"
596 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
598 export NOTMUCH_DATABASE=${MAIL_DIR}
599 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
601 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
602 printf("test.key1 = %s\n", val);
603 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
604 printf("test.key2 = %s\n", val);
607 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
608 unset NOTMUCH_DATABASE
609 cat <<'EOF' >EXPECTED
611 test.key1 = testvalue1
612 test.key2 = testvalue2
615 test_expect_equal_file EXPECTED OUTPUT
617 test_begin_subtest "NOTMUCH_DATABASE overrides config"
618 cp notmuch-config notmuch-config.bak
619 notmuch config set database.path /nonexistent
620 export NOTMUCH_DATABASE=${MAIL_DIR}
621 cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
623 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
624 printf("test.key1 = %s\n", val);
625 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
626 printf("test.key2 = %s\n", val);
629 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
630 unset NOTMUCH_DATABASE
631 cat <<'EOF' >EXPECTED
633 test.key1 = testvalue1
634 test.key2 = testvalue2
637 cp notmuch-config.bak notmuch-config
638 test_expect_equal_file EXPECTED OUTPUT
641 #include <notmuch-test.h>
643 int main (int argc, char** argv)
645 notmuch_database_t *db;
647 notmuch_status_t stat;
650 for (int i = 1; i < argc; i++)
651 if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
653 stat = notmuch_database_load_config (argv[1],
658 if (stat != NOTMUCH_STATUS_SUCCESS && stat != NOTMUCH_STATUS_NO_CONFIG) {
659 fprintf (stderr, "error opening database\n%d: %s\n%s\n", stat,
660 notmuch_status_to_string (stat), msg ? msg : "");
666 test_begin_subtest "notmuch_database_get_config (ndlc)"
667 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
669 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
670 printf("test.key1 = %s\n", val);
671 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
672 printf("test.key2 = %s\n", val);
675 cat <<'EOF' >EXPECTED
677 test.key1 = testvalue1
678 test.key2 = testvalue2
681 test_expect_equal_file EXPECTED OUTPUT
684 test_begin_subtest "notmuch_database_get_config_list: all pairs (ndlc)"
685 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
687 notmuch_config_list_t *list;
688 EXPECT0(notmuch_database_get_config_list (db, "", &list));
689 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
690 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
692 notmuch_config_list_destroy (list);
695 cat <<'EOF' >EXPECTED
698 key with spaces value, with, spaces!
704 test_expect_equal_file EXPECTED OUTPUT
706 test_begin_subtest "notmuch_database_get_config_list: one prefix (ndlc)"
707 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
709 notmuch_config_list_t *list;
710 EXPECT0(notmuch_database_get_config_list (db, "test.key", &list));
711 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
712 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
714 notmuch_config_list_destroy (list);
717 cat <<'EOF' >EXPECTED
723 test_expect_equal_file EXPECTED OUTPUT
725 test_begin_subtest "list by keys (ndlc)"
726 notmuch config set search.exclude_tags "foo;bar;fub"
727 notmuch config set new.ignore "sekrit_junk"
728 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
730 notmuch_config_key_t key;
731 for (key = NOTMUCH_CONFIG_FIRST;
732 key < NOTMUCH_CONFIG_LAST;
733 key = (notmuch_config_key_t)(key + 1)) {
734 const char *val = notmuch_config_get (db, key);
735 printf("%02d: '%s'\n", key, val ? val : "NULL" );
739 cat <<'EOF' >EXPECTED
743 02: 'MAIL_DIR/.notmuch/hooks'
744 03: 'MAIL_DIR/.notmuch/backups'
749 08: 'test_suite@notmuchmail.org'
750 09: 'test_suite_other@notmuchmail.org;test_suite@otherdomain.org'
751 10: 'Notmuch Test Suite'
756 test_expect_equal_file EXPECTED OUTPUT
758 test_begin_subtest "load default values (ndlc, nonexistent config)"
759 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} /nonexistent %NULL%
761 notmuch_config_key_t key;
762 for (key = NOTMUCH_CONFIG_FIRST;
763 key < NOTMUCH_CONFIG_LAST;
764 key = (notmuch_config_key_t)(key + 1)) {
765 const char *val = notmuch_config_get (db, key);
766 printf("%02d: '%s'\n", key, val ? val : "NULL" );
771 _libconfig_sanitize < OUTPUT > OUTPUT.clean
773 cat <<'EOF' >EXPECTED
777 02: 'MAIL_DIR/.notmuch/hooks'
778 03: 'MAIL_DIR/.notmuch/backups'
783 08: 'USERNAME@localhost'
790 test_expect_equal_file EXPECTED OUTPUT.clean
793 test_begin_subtest "override config from \${HOME}/.notmuch-config (ndlc)"
794 ovconfig=${HOME}/.notmuch-config
795 cp ${NOTMUCH_CONFIG} ${ovconfig}
796 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
798 notmuch --config=${ovconfig} config set test.key1 overridden-home
799 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
801 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
802 printf("test.key1 = %s\n", val);
803 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
804 printf("test.key2 = %s\n", val);
808 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
809 cat <<'EOF' >EXPECTED
811 test.key1 = overridden-home
812 test.key2 = testvalue2
815 test_expect_equal_file EXPECTED OUTPUT
818 test_begin_subtest "notmuch_config_get_pairs: prefix (ndlc)"
819 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
821 notmuch_config_pairs_t *list;
822 for (list = notmuch_config_get_pairs (db, "user.");
823 notmuch_config_pairs_valid (list);
824 notmuch_config_pairs_move_to_next (list)) {
825 printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list));
827 notmuch_config_pairs_destroy (list);
830 cat <<'EOF' >EXPECTED
832 user.name Notmuch Test Suite
833 user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org
834 user.primary_email test_suite@notmuchmail.org
837 test_expect_equal_file EXPECTED OUTPUT
839 test_begin_subtest "notmuch_config_get_pairs: all pairs (ndlc)"
840 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
842 notmuch_config_pairs_t *list;
843 for (list = notmuch_config_get_pairs (db, "");
844 notmuch_config_pairs_valid (list);
845 notmuch_config_pairs_move_to_next (list)) {
846 printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list));
848 notmuch_config_pairs_destroy (list);
851 cat <<'EOF' >EXPECTED
854 database.autocommit 8000
855 database.backup_dir MAIL_DIR/.notmuch/backups
856 database.hook_dir MAIL_DIR/.notmuch/hooks
857 database.mail_root MAIL_DIR
858 database.path MAIL_DIR
859 key with spaces value, with, spaces!
860 maildir.synchronize_flags true
861 new.ignore sekrit_junk
862 new.tags unread;inbox
863 search.exclude_tags foo;bar;fub
864 show.extra_headers (null)
867 user.name Notmuch Test Suite
868 user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org
869 user.primary_email test_suite@notmuchmail.org
873 test_expect_equal_file EXPECTED OUTPUT
876 #include <notmuch-test.h>
877 int main (int argc, char **argv) {
878 notmuch_status_t stat;
879 notmuch_database_t *db = NULL;
883 printf("db == NULL: %d\n", db == NULL);
887 test_begin_subtest "open: database set to null on missing config"
888 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
889 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
890 NOTMUCH_DATABASE_MODE_READ_ONLY,
891 "/nonexistent", NULL, &db, NULL);
898 test_expect_equal_file EXPECTED OUTPUT
900 test_begin_subtest "open: database set to null on missing config (env)"
901 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
902 export NOTMUCH_CONFIG="/nonexistent"
903 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
904 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
905 NOTMUCH_DATABASE_MODE_READ_ONLY,
906 NULL, NULL, &db, NULL);
908 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
914 test_expect_equal_file EXPECTED OUTPUT
916 test_begin_subtest "create: database set to null on missing config"
917 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent"
918 notmuch_status_t st = notmuch_database_create_with_config(argv[1],argv[2], NULL, &db, NULL);
925 test_expect_equal_file EXPECTED OUTPUT
927 test_begin_subtest "create: database set to null on missing config (env)"
928 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
929 export NOTMUCH_CONFIG="/nonexistent"
930 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
931 notmuch_status_t st = notmuch_database_create_with_config(argv[1],
932 NULL, NULL, &db, NULL);
934 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
940 test_expect_equal_file EXPECTED OUTPUT
942 test_begin_subtest "load_config: database set non-null on missing config"
943 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent"
944 notmuch_status_t st = notmuch_database_load_config(argv[1],argv[2], NULL, &db, NULL);
951 test_expect_equal_file EXPECTED OUTPUT
953 test_begin_subtest "load_config: database non-null on missing config (env)"
954 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
955 export NOTMUCH_CONFIG="/nonexistent"
956 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
957 notmuch_status_t st = notmuch_database_load_config(argv[1], NULL, NULL, &db, NULL);
959 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
965 test_expect_equal_file EXPECTED OUTPUT
967 test_begin_subtest "load_config: database set to NULL on fatal error"
968 cat c_head3 - c_tail3 <<'EOF' | test_C
969 notmuch_status_t st = notmuch_database_load_config("relative", NULL, NULL, &db, NULL);
976 test_expect_equal_file EXPECTED OUTPUT
978 test_begin_subtest "open: database parameter overrides implicit config"
979 cp $NOTMUCH_CONFIG ${NOTMUCH_CONFIG}.bak
980 notmuch config set database.path ${MAIL_DIR}/nonexistent
981 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
982 const char *path = NULL;
983 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
984 NOTMUCH_DATABASE_MODE_READ_ONLY,
985 NULL, NULL, &db, NULL);
986 printf ("status: %d\n", st);
987 path = notmuch_database_get_path (db);
988 printf ("path: %s\n", path ? path : "(null)");
990 cp ${NOTMUCH_CONFIG}.bak ${NOTMUCH_CONFIG}
998 notmuch_dir_sanitize < OUTPUT > OUTPUT.clean
999 test_expect_equal_file EXPECTED OUTPUT.clean
1002 notmuch_status_t st = notmuch_database_open_with_config(NULL,
1003 NOTMUCH_DATABASE_MODE_READ_ONLY,
1004 "", NULL, &db, NULL);
1005 printf ("status == SUCCESS: %d\n", st == NOTMUCH_STATUS_SUCCESS);
1007 const char *mail_root = NULL;
1008 mail_root = notmuch_config_get (db, NOTMUCH_CONFIG_MAIL_ROOT);
1009 printf ("mail_root: %s\n", mail_root ? mail_root : "(null)");
1013 cat <<EOF> EXPECTED.common
1015 status == SUCCESS: 0
1020 test_begin_subtest "open/error: config=empty with no mail root in db "
1021 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
1022 unset NOTMUCH_CONFIG
1023 cat c_head3 c_body c_tail3 | test_C
1024 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
1025 notmuch_dir_sanitize < OUTPUT > OUTPUT.clean
1026 test_expect_equal_file EXPECTED.common OUTPUT.clean
1028 test_begin_subtest "open/error: config=empty with no mail root in db (xdg)"
1029 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
1030 unset NOTMUCH_CONFIG
1032 mkdir -p home/.local/share/notmuch
1033 mv mail/.notmuch home/.local/share/notmuch/default
1034 cat c_head3 c_body c_tail3 | test_C
1036 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
1037 notmuch_dir_sanitize < OUTPUT > OUTPUT.clean
1038 test_expect_equal_file EXPECTED.common OUTPUT.clean