X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=test%2FT590-libconfig.sh;h=189381f7f9b974747685ae13a7a1bb74ab42226c;hb=7406abf5e0596b7865e7fe31ef9e92727ed15c54;hp=edbba6c47f753b58f5152c4463016670a7e9ed95;hpb=0c6db22930b58fcea972e71b45f7ea0e6055ed20;p=notmuch diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index edbba6c4..189381f7 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -5,6 +5,25 @@ test_description="library config API" add_email_corpus +_libconfig_sanitize() { + ${NOTMUCH_PYTHON} /dev/fd/3 3<<'EOF' +import os, sys, pwd, socket + +pw = pwd.getpwuid(os.getuid()) +user = pw.pw_name +name = pw.pw_gecos.partition(",")[0] +fqdn = socket.getaddrinfo(socket.gethostname(), 0, 0, + socket.SOCK_STREAM, 0, socket.AI_CANONNAME)[0][3] +for l in sys.stdin: + if l[:4] == "08: ": + l = l.replace(user, "USERNAME", 1).replace("@" + fqdn, "@FQDN", 1) + l = l.replace(".(none)", "", 1).replace(".localdomain", "", 1) + elif l[:4] == "10: ": + l = l.replace("'" + name, "'USER_FULL_NAME", 1) + sys.stdout.write(l) +EOF +} + cat < c_head #include #include @@ -380,27 +399,30 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} '' %NULL% key < NOTMUCH_CONFIG_LAST; key = (notmuch_config_key_t)(key + 1)) { const char *val = notmuch_config_get (db, key); - printf("%s\n", val ? val : "NULL" ); + printf("%02d: '%s'\n", key, val ? val : "NULL" ); } } EOF + +_libconfig_sanitize < OUTPUT > OUTPUT.clean + cat <<'EOF' >EXPECTED == stdout == -MAIL_DIR -MAIL_DIR -MAIL_DIR/.notmuch/hooks -MAIL_DIR/.notmuch/backups - -inbox;unread -NULL -true -NULL -NULL -NULL +00: 'MAIL_DIR' +01: 'MAIL_DIR' +02: 'MAIL_DIR/.notmuch/hooks' +03: 'MAIL_DIR/.notmuch/backups' +04: '' +05: 'unread;inbox' +06: '' +07: 'true' +08: 'USERNAME@FQDN' +09: 'NULL' +10: 'USER_FULL_NAME' == stderr == EOF unset MAILDIR -test_expect_equal_file EXPECTED OUTPUT +test_expect_equal_file EXPECTED OUTPUT.clean backup_database test_begin_subtest "override config from \${NOTMUCH_CONFIG}" @@ -543,8 +565,8 @@ cat <<'EOF' >EXPECTED == stdout == == stderr == error opening database -Something went wrong trying to read or write a file -Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory. +No database found +Error: could not locate database. EOF test_expect_equal_file EXPECTED OUTPUT @@ -623,9 +645,6 @@ EOF test_begin_subtest "notmuch_database_get_config (ndlc)" -echo NOTMUCH_CONFIG=$NOTMUCH_CONFIG -echo NOTMUCH_PROFILE=$NOTMUCH_PROFILE -echo HOME=$HOME cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL% { EXPECT0(notmuch_database_get_config (db, "test.key1", &val)); @@ -694,23 +713,23 @@ cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL% key < NOTMUCH_CONFIG_LAST; key = (notmuch_config_key_t)(key + 1)) { const char *val = notmuch_config_get (db, key); - printf("%s\n", val ? val : "NULL" ); + printf("%02d: '%s'\n", key, val ? val : "NULL" ); } } EOF cat <<'EOF' >EXPECTED == stdout == -MAIL_DIR -MAIL_DIR -MAIL_DIR/.notmuch/hooks -MAIL_DIR/.notmuch/backups -foo;bar;fub -unread;inbox; -sekrit_junk -true -test_suite@notmuchmail.org -test_suite_other@notmuchmail.org;test_suite@otherdomain.org -Notmuch Test Suite +00: 'MAIL_DIR' +01: 'MAIL_DIR' +02: 'MAIL_DIR/.notmuch/hooks' +03: 'MAIL_DIR/.notmuch/backups' +04: 'foo;bar;fub' +05: 'unread;inbox' +06: 'sekrit_junk' +07: 'true' +08: 'test_suite@notmuchmail.org' +09: 'test_suite_other@notmuchmail.org;test_suite@otherdomain.org' +10: 'Notmuch Test Suite' == stderr == EOF test_expect_equal_file EXPECTED OUTPUT @@ -723,26 +742,29 @@ cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} /nonexistent %NULL% key < NOTMUCH_CONFIG_LAST; key = (notmuch_config_key_t)(key + 1)) { const char *val = notmuch_config_get (db, key); - printf("%s\n", val ? val : "NULL" ); + printf("%02d: '%s'\n", key, val ? val : "NULL" ); } } EOF + +_libconfig_sanitize < OUTPUT > OUTPUT.clean + cat <<'EOF' >EXPECTED == stdout == -MAIL_DIR -MAIL_DIR -MAIL_DIR/.notmuch/hooks -MAIL_DIR/.notmuch/backups - -inbox;unread -NULL -true -NULL -NULL -NULL +00: 'MAIL_DIR' +01: 'MAIL_DIR' +02: 'MAIL_DIR/.notmuch/hooks' +03: 'MAIL_DIR/.notmuch/backups' +04: '' +05: 'unread;inbox' +06: '' +07: 'true' +08: 'USERNAME@FQDN' +09: 'NULL' +10: 'USER_FULL_NAME' == stderr == EOF -test_expect_equal_file EXPECTED OUTPUT +test_expect_equal_file EXPECTED OUTPUT.clean backup_database test_begin_subtest "override config from \${HOME}/.notmuch-config (ndlc)" @@ -770,5 +792,59 @@ EOF test_expect_equal_file EXPECTED OUTPUT restore_database +test_begin_subtest "notmuch_config_get_pairs: prefix (ndlc)" +cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL% +{ + notmuch_config_pairs_t *list; + for (list = notmuch_config_get_pairs (db, "user."); + notmuch_config_pairs_valid (list); + notmuch_config_pairs_move_to_next (list)) { + printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list)); + } + notmuch_config_pairs_destroy (list); +} +EOF +cat <<'EOF' >EXPECTED +== stdout == +user.name Notmuch Test Suite +user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org +user.primary_email test_suite@notmuchmail.org +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "notmuch_config_get_pairs: all pairs (ndlc)" +cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL% +{ + notmuch_config_pairs_t *list; + for (list = notmuch_config_get_pairs (db, ""); + notmuch_config_pairs_valid (list); + notmuch_config_pairs_move_to_next (list)) { + printf("%s %s\n", notmuch_config_pairs_key (list), notmuch_config_pairs_value(list)); + } + notmuch_config_pairs_destroy (list); +} +EOF +cat <<'EOF' >EXPECTED +== stdout == +aaabefore beforeval +database.backup_dir MAIL_DIR/.notmuch/backups +database.hook_dir MAIL_DIR/.notmuch/hooks +database.mail_root MAIL_DIR +database.path MAIL_DIR +key with spaces value, with, spaces! +maildir.synchronize_flags true +new.ignore sekrit_junk +new.tags unread;inbox +search.exclude_tags foo;bar;fub +test.key1 testvalue1 +test.key2 testvalue2 +user.name Notmuch Test Suite +user.other_email test_suite_other@notmuchmail.org;test_suite@otherdomain.org +user.primary_email test_suite@notmuchmail.org +zzzafter afterval +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT test_done