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)
28 #include <notmuch-test.h>
30 int main (int argc, char** argv)
32 notmuch_database_t *db;
34 notmuch_status_t stat;
37 for (int i = 1; i < argc; i++)
38 if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
40 stat = notmuch_database_open_with_config (argv[1],
41 NOTMUCH_DATABASE_MODE_READ_WRITE,
46 if (stat != NOTMUCH_STATUS_SUCCESS) {
47 fprintf (stderr, "error opening database\n%s\n%s\n", notmuch_status_to_string (stat), msg ? msg : "");
53 EXPECT0(notmuch_database_destroy(db));
57 test_begin_subtest "notmuch_database_{set,get}_config"
58 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG}
60 EXPECT0(notmuch_database_set_config (db, "test.key1", "testvalue1"));
61 EXPECT0(notmuch_database_set_config (db, "test.key2", "testvalue2"));
62 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
63 printf("test.key1 = %s\n", val);
64 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
65 printf("test.key2 = %s\n", val);
70 test.key1 = testvalue1
71 test.key2 = testvalue2
74 test_expect_equal_file EXPECTED OUTPUT
77 test_begin_subtest "notmuch_database_get_config_list: empty list"
78 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
80 notmuch_config_list_t *list;
81 EXPECT0(notmuch_database_get_config_list (db, "nonexistent", &list));
82 printf("valid = %d\n", notmuch_config_list_valid (list));
83 notmuch_config_list_destroy (list);
91 test_expect_equal_file EXPECTED OUTPUT
93 test_begin_subtest "notmuch_database_get_config_list: closed db"
94 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
96 notmuch_config_list_t *list;
97 EXPECT0(notmuch_database_close (db));
98 stat = notmuch_database_get_config_list (db, "nonexistent", &list);
99 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
102 cat <<'EOF' >EXPECTED
107 test_expect_equal_file EXPECTED OUTPUT
109 test_begin_subtest "notmuch_database_get_config_list: all pairs"
110 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
112 notmuch_config_list_t *list;
113 EXPECT0(notmuch_database_set_config (db, "zzzafter", "afterval"));
114 EXPECT0(notmuch_database_set_config (db, "aaabefore", "beforeval"));
115 EXPECT0(notmuch_database_get_config_list (db, "", &list));
116 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
117 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
119 notmuch_config_list_destroy (list);
122 cat <<'EOF' >EXPECTED
130 test_expect_equal_file EXPECTED OUTPUT
132 test_begin_subtest "notmuch_database_get_config_list: all pairs (closed db)"
133 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
135 notmuch_config_list_t *list;
136 EXPECT0(notmuch_database_get_config_list (db, "", &list));
137 EXPECT0(notmuch_database_close (db));
138 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
139 printf("%s %d\n", notmuch_config_list_key (list), NULL == notmuch_config_list_value(list));
141 notmuch_config_list_destroy (list);
144 cat <<'EOF' >EXPECTED
152 test_expect_equal_file EXPECTED OUTPUT
154 test_begin_subtest "notmuch_database_get_config_list: one prefix"
155 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
157 notmuch_config_list_t *list;
158 EXPECT0(notmuch_database_get_config_list (db, "test.key", &list));
159 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
160 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
162 notmuch_config_list_destroy (list);
165 cat <<'EOF' >EXPECTED
171 test_expect_equal_file EXPECTED OUTPUT
173 test_begin_subtest "dump config"
174 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
176 EXPECT0(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));
179 notmuch dump --include=config >OUTPUT
180 cat <<'EOF' >EXPECTED
181 #notmuch-dump batch-tag:3 config
182 #@ aaabefore beforeval
183 #@ key%20with%20spaces value,%20with,%20spaces%21
184 #@ test.key1 testvalue1
185 #@ test.key2 testvalue2
188 test_expect_equal_file EXPECTED OUTPUT
190 test_begin_subtest "restore config"
191 notmuch dump --include=config >EXPECTED
192 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
194 EXPECT0(notmuch_database_set_config (db, "test.key1", "mutatedvalue"));
197 notmuch restore --include=config <EXPECTED
198 notmuch dump --include=config >OUTPUT
199 test_expect_equal_file EXPECTED OUTPUT
202 test_begin_subtest "override config from file"
203 notmuch config set test.key1 overridden
204 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG}
206 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
207 printf("test.key1 = %s\n", val);
208 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
209 printf("test.key2 = %s\n", val);
212 cat <<'EOF' >EXPECTED
214 test.key1 = overridden
215 test.key2 = testvalue2
218 test_expect_equal_file EXPECTED OUTPUT
221 test_begin_subtest "NOTMUCH_CONFIG_HOOK_DIR: traditional"
222 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
224 const char *val = notmuch_config_get (db, NOTMUCH_CONFIG_HOOK_DIR);
225 printf("database.hook_dir = %s\n", val);
228 cat <<'EOF' >EXPECTED
230 database.hook_dir = MAIL_DIR/.notmuch/hooks
233 test_expect_equal_file EXPECTED OUTPUT
235 test_begin_subtest "NOTMUCH_CONFIG_HOOK_DIR: xdg"
236 dir="${HOME}/.config/notmuch/default/hooks"
238 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
240 const char *val = notmuch_config_get (db, NOTMUCH_CONFIG_HOOK_DIR);
241 printf("database.hook_dir = %s\n", val);
244 cat <<'EOF' >EXPECTED
246 database.hook_dir = CWD/home/.config/notmuch/default/hooks
250 test_expect_equal_file EXPECTED OUTPUT
252 test_begin_subtest "notmuch_config_get_values"
253 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
255 notmuch_config_values_t *values;
256 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, "a;b;c"));
257 for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS);
258 notmuch_config_values_valid (values);
259 notmuch_config_values_move_to_next (values))
261 puts (notmuch_config_values_get (values));
265 cat <<'EOF' >EXPECTED
272 test_expect_equal_file EXPECTED OUTPUT
275 test_begin_subtest "notmuch_config_get_values (ignore leading/trailing whitespace)"
276 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
278 notmuch_config_values_t *values;
279 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, " a ; b c ; d "));
280 for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS);
281 notmuch_config_values_valid (values);
282 notmuch_config_values_move_to_next (values))
284 puts (notmuch_config_values_get (values));
288 cat <<'EOF' >EXPECTED
295 test_expect_equal_file EXPECTED OUTPUT
298 test_begin_subtest "notmuch_config_get_values_string"
299 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
301 notmuch_config_values_t *values;
302 EXPECT0(notmuch_database_set_config (db, "test.list", "x;y;z"));
303 for (values = notmuch_config_get_values_string (db, "test.list");
304 notmuch_config_values_valid (values);
305 notmuch_config_values_move_to_next (values))
307 puts (notmuch_config_values_get (values));
311 cat <<'EOF' >EXPECTED
318 test_expect_equal_file EXPECTED OUTPUT
321 test_begin_subtest "notmuch_config_get_values (restart)"
322 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
324 notmuch_config_values_t *values;
325 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, "a;b;c"));
326 for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS);
327 notmuch_config_values_valid (values);
328 notmuch_config_values_move_to_next (values))
330 puts (notmuch_config_values_get (values));
332 for (notmuch_config_values_start (values);
333 notmuch_config_values_valid (values);
334 notmuch_config_values_move_to_next (values))
336 puts (notmuch_config_values_get (values));
340 cat <<'EOF' >EXPECTED
350 test_expect_equal_file EXPECTED OUTPUT
354 test_begin_subtest "notmuch_config_get_values, trailing ;"
355 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
357 notmuch_config_values_t *values;
358 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, "a;b;c"));
359 for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS);
360 notmuch_config_values_valid (values);
361 notmuch_config_values_move_to_next (values))
363 puts (notmuch_config_values_get (values));
367 cat <<'EOF' >EXPECTED
374 test_expect_equal_file EXPECTED OUTPUT
378 test_begin_subtest "get config by key"
379 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG}
381 printf("before = %s\n", notmuch_config_get (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS));
382 EXPECT0(notmuch_database_set_config (db, "maildir.synchronize_flags", "false"));
383 printf("after = %s\n", notmuch_config_get (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS));
386 cat <<'EOF' >EXPECTED
392 test_expect_equal_file EXPECTED OUTPUT
396 test_begin_subtest "set config by key"
397 notmuch config set test.key1 overridden
398 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG}
400 printf("before = %s\n", notmuch_config_get (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS));
401 EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS, "false"));
402 printf("after = %s\n", notmuch_config_get (db, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS));
405 cat <<'EOF' >EXPECTED
411 test_expect_equal_file EXPECTED OUTPUT
414 test_begin_subtest "load default values"
415 export MAILDIR=${MAIL_DIR}
416 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} '' %NULL%
418 notmuch_config_key_t key;
419 for (key = NOTMUCH_CONFIG_FIRST;
420 key < NOTMUCH_CONFIG_LAST;
421 key = (notmuch_config_key_t)(key + 1)) {
422 const char *val = notmuch_config_get (db, key);
423 printf("%02d: '%s'\n", key, val ? val : "NULL" );
428 _libconfig_sanitize < OUTPUT > OUTPUT.clean
430 cat <<'EOF' >EXPECTED
434 02: 'MAIL_DIR/.notmuch/hooks'
435 03: 'MAIL_DIR/.notmuch/backups'
440 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
644 #include <notmuch-test.h>
646 int main (int argc, char** argv)
648 notmuch_database_t *db;
650 notmuch_status_t stat;
653 for (int i = 1; i < argc; i++)
654 if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
656 stat = notmuch_database_load_config (argv[1],
661 if (stat != NOTMUCH_STATUS_SUCCESS && stat != NOTMUCH_STATUS_NO_CONFIG) {
662 fprintf (stderr, "error opening database\n%d: %s\n%s\n", stat,
663 notmuch_status_to_string (stat), msg ? msg : "");
669 test_begin_subtest "notmuch_database_get_config (ndlc)"
670 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
672 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
673 printf("test.key1 = %s\n", val);
674 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
675 printf("test.key2 = %s\n", val);
678 cat <<'EOF' >EXPECTED
680 test.key1 = testvalue1
681 test.key2 = testvalue2
684 test_expect_equal_file EXPECTED OUTPUT
687 test_begin_subtest "notmuch_database_get_config_list: all pairs (ndlc)"
688 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
690 notmuch_config_list_t *list;
691 EXPECT0(notmuch_database_get_config_list (db, "", &list));
692 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
693 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
695 notmuch_config_list_destroy (list);
698 cat <<'EOF' >EXPECTED
701 key with spaces value, with, spaces!
707 test_expect_equal_file EXPECTED OUTPUT
709 test_begin_subtest "notmuch_database_get_config_list: one prefix (ndlc)"
710 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
712 notmuch_config_list_t *list;
713 EXPECT0(notmuch_database_get_config_list (db, "test.key", &list));
714 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
715 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
717 notmuch_config_list_destroy (list);
720 cat <<'EOF' >EXPECTED
726 test_expect_equal_file EXPECTED OUTPUT
728 test_begin_subtest "list by keys (ndlc)"
729 notmuch config set search.exclude_tags "foo;bar;fub"
730 notmuch config set new.ignore "sekrit_junk"
731 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
733 notmuch_config_key_t key;
734 for (key = NOTMUCH_CONFIG_FIRST;
735 key < NOTMUCH_CONFIG_LAST;
736 key = (notmuch_config_key_t)(key + 1)) {
737 const char *val = notmuch_config_get (db, key);
738 printf("%02d: '%s'\n", key, val ? val : "NULL" );
742 cat <<'EOF' >EXPECTED
746 02: 'MAIL_DIR/.notmuch/hooks'
747 03: 'MAIL_DIR/.notmuch/backups'
752 08: 'test_suite@notmuchmail.org'
753 09: 'test_suite_other@notmuchmail.org;test_suite@otherdomain.org'
754 10: 'Notmuch Test Suite'
758 test_expect_equal_file EXPECTED OUTPUT
760 test_begin_subtest "load default values (ndlc, nonexistent config)"
761 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} /nonexistent %NULL%
763 notmuch_config_key_t key;
764 for (key = NOTMUCH_CONFIG_FIRST;
765 key < NOTMUCH_CONFIG_LAST;
766 key = (notmuch_config_key_t)(key + 1)) {
767 const char *val = notmuch_config_get (db, key);
768 printf("%02d: '%s'\n", key, val ? val : "NULL" );
773 _libconfig_sanitize < OUTPUT > OUTPUT.clean
775 cat <<'EOF' >EXPECTED
779 02: 'MAIL_DIR/.notmuch/hooks'
780 03: 'MAIL_DIR/.notmuch/backups'
785 08: 'USERNAME@localhost'
791 test_expect_equal_file EXPECTED OUTPUT.clean
794 test_begin_subtest "override config from \${HOME}/.notmuch-config (ndlc)"
795 ovconfig=${HOME}/.notmuch-config
796 cp ${NOTMUCH_CONFIG} ${ovconfig}
797 old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
799 notmuch --config=${ovconfig} config set test.key1 overridden-home
800 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
802 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
803 printf("test.key1 = %s\n", val);
804 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
805 printf("test.key2 = %s\n", val);
809 export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
810 cat <<'EOF' >EXPECTED
812 test.key1 = overridden-home
813 test.key2 = testvalue2
816 test_expect_equal_file EXPECTED OUTPUT
819 test_begin_subtest "notmuch_config_get_pairs: prefix (ndlc)"
820 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
822 notmuch_config_pairs_t *list;
823 for (list = notmuch_config_get_pairs (db, "user.");
824 notmuch_config_pairs_valid (list);
825 notmuch_config_pairs_move_to_next (list)) {
826 printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list));
828 notmuch_config_pairs_destroy (list);
831 cat <<'EOF' >EXPECTED
833 user.name Notmuch Test Suite
834 user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org
835 user.primary_email test_suite@notmuchmail.org
838 test_expect_equal_file EXPECTED OUTPUT
840 test_begin_subtest "notmuch_config_get_pairs: all pairs (ndlc)"
841 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
843 notmuch_config_pairs_t *list;
844 for (list = notmuch_config_get_pairs (db, "");
845 notmuch_config_pairs_valid (list);
846 notmuch_config_pairs_move_to_next (list)) {
847 printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list));
849 notmuch_config_pairs_destroy (list);
852 cat <<'EOF' >EXPECTED
855 database.autocommit 8000
856 database.backup_dir MAIL_DIR/.notmuch/backups
857 database.hook_dir MAIL_DIR/.notmuch/hooks
858 database.mail_root MAIL_DIR
859 database.path MAIL_DIR
860 key with spaces value, with, spaces!
861 maildir.synchronize_flags true
862 new.ignore sekrit_junk
863 new.tags unread;inbox
864 search.exclude_tags foo;bar;fub
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 notmuch config set database.path ${MAIL_DIR}/nonexistent
980 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
981 const char *path = NULL;
982 notmuch_status_t st = notmuch_database_open_with_config(argv[1],
983 NOTMUCH_DATABASE_MODE_READ_ONLY,
984 NULL, NULL, &db, NULL);
985 printf ("status: %d\n", st);
986 path = notmuch_database_get_path (db);
987 printf ("path: %s\n", path ? path : "(null)");
996 notmuch_dir_sanitize < OUTPUT > OUTPUT.clean
997 test_expect_equal_file EXPECTED OUTPUT.clean