X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=test%2FT590-libconfig.sh;h=46f3a76d574fbd8c485179ac6e241a5cc93ed07a;hp=b4abbd78f09d9ea7e6a81574f199cd1a461111e7;hb=HEAD;hpb=8f0b84789d4fda0182e073b68b73160c9b94a4b7 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index b4abbd78..9326ba3e 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -23,8 +23,6 @@ EOF } cat < c_head -#include -#include #include int main (int argc, char** argv) @@ -272,6 +270,29 @@ EOF test_expect_equal_file EXPECTED OUTPUT restore_database +test_begin_subtest "notmuch_config_get_values (ignore leading/trailing whitespace)" +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL% +{ + notmuch_config_values_t *values; + EXPECT0(notmuch_config_set (db, NOTMUCH_CONFIG_NEW_TAGS, " a ; b c ; d ")); + for (values = notmuch_config_get_values (db, NOTMUCH_CONFIG_NEW_TAGS); + notmuch_config_values_valid (values); + notmuch_config_values_move_to_next (values)) + { + puts (notmuch_config_values_get (values)); + } +} +EOF +cat <<'EOF' >EXPECTED +== stdout == +a +b c +d +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT +restore_database + test_begin_subtest "notmuch_config_get_values_string" cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL% { @@ -418,6 +439,8 @@ cat <<'EOF' >EXPECTED 09: 'NULL' 10: 'USER_FULL_NAME' 11: '8000' +12: 'NULL' +13: '' == stderr == EOF unset MAILDIR @@ -616,8 +639,6 @@ cp notmuch-config.bak notmuch-config test_expect_equal_file EXPECTED OUTPUT cat < c_head2 -#include -#include #include int main (int argc, char** argv) @@ -705,6 +726,7 @@ test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "list by keys (ndlc)" notmuch config set search.exclude_tags "foo;bar;fub" notmuch config set new.ignore "sekrit_junk" +notmuch config set index.as_text "text/" cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL% { notmuch_config_key_t key; @@ -730,6 +752,8 @@ cat <<'EOF' >EXPECTED 09: 'test_suite_other@notmuchmail.org;test_suite@otherdomain.org' 10: 'Notmuch Test Suite' 11: '8000' +12: 'NULL' +13: 'text/' == stderr == EOF test_expect_equal_file EXPECTED OUTPUT @@ -763,6 +787,8 @@ cat <<'EOF' >EXPECTED 09: 'NULL' 10: 'USER_FULL_NAME' 11: '8000' +12: 'NULL' +13: '' == stderr == EOF test_expect_equal_file EXPECTED OUTPUT.clean @@ -834,11 +860,13 @@ database.backup_dir MAIL_DIR/.notmuch/backups database.hook_dir MAIL_DIR/.notmuch/hooks database.mail_root MAIL_DIR database.path MAIL_DIR +index.as_text text/ key with spaces value, with, spaces! maildir.synchronize_flags true new.ignore sekrit_junk new.tags unread;inbox search.exclude_tags foo;bar;fub +show.extra_headers (null) test.key1 testvalue1 test.key2 testvalue2 user.name Notmuch Test Suite @@ -876,13 +904,13 @@ test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "open: database set to null on missing config (env)" old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG} -NOTMUCH_CONFIG="/nonexistent" +export NOTMUCH_CONFIG="/nonexistent" cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} notmuch_status_t st = notmuch_database_open_with_config(argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, NULL, NULL, &db, NULL); EOF -NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} cat < EXPECTED == stdout == db == NULL: 1 @@ -903,12 +931,12 @@ test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "create: database set to null on missing config (env)" old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG} -NOTMUCH_CONFIG="/nonexistent" +export NOTMUCH_CONFIG="/nonexistent" cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} notmuch_status_t st = notmuch_database_create_with_config(argv[1], NULL, NULL, &db, NULL); EOF -NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} cat < EXPECTED == stdout == db == NULL: 1 @@ -929,11 +957,11 @@ test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "load_config: database non-null on missing config (env)" old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG} -NOTMUCH_CONFIG="/nonexistent" +export NOTMUCH_CONFIG="/nonexistent" cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} notmuch_status_t st = notmuch_database_load_config(argv[1], NULL, NULL, &db, NULL); EOF -NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} cat < EXPECTED == stdout == db == NULL: 0 @@ -942,7 +970,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "load_config: database set to NULL on fatal error" -test_subtest_known_broken cat c_head3 - c_tail3 <<'EOF' | test_C notmuch_status_t st = notmuch_database_load_config("relative", NULL, NULL, &db, NULL); EOF @@ -953,4 +980,66 @@ db == NULL: 1 EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "open: database parameter overrides implicit config" +cp $NOTMUCH_CONFIG ${NOTMUCH_CONFIG}.bak +notmuch config set database.path ${MAIL_DIR}/nonexistent +cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} + const char *path = NULL; + notmuch_status_t st = notmuch_database_open_with_config(argv[1], + NOTMUCH_DATABASE_MODE_READ_ONLY, + NULL, NULL, &db, NULL); + printf ("status: %d\n", st); + path = notmuch_database_get_path (db); + printf ("path: %s\n", path ? path : "(null)"); +EOF +cp ${NOTMUCH_CONFIG}.bak ${NOTMUCH_CONFIG} +cat < EXPECTED +== stdout == +status: 0 +path: MAIL_DIR +db == NULL: 0 +== stderr == +EOF +notmuch_dir_sanitize < OUTPUT > OUTPUT.clean +test_expect_equal_file EXPECTED OUTPUT.clean + +cat < c_body + notmuch_status_t st = notmuch_database_open_with_config(NULL, + NOTMUCH_DATABASE_MODE_READ_ONLY, + "", NULL, &db, NULL); + printf ("status == SUCCESS: %d\n", st == NOTMUCH_STATUS_SUCCESS); + if (db) { + const char *mail_root = NULL; + mail_root = notmuch_config_get (db, NOTMUCH_CONFIG_MAIL_ROOT); + printf ("mail_root: %s\n", mail_root ? mail_root : "(null)"); + } +EOF + +cat < EXPECTED.common +== stdout == +status == SUCCESS: 0 +db == NULL: 1 +== stderr == +EOF + +test_begin_subtest "open/error: config=empty with no mail root in db " +old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG} +unset NOTMUCH_CONFIG +cat c_head3 c_body c_tail3 | test_C +export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +notmuch_dir_sanitize < OUTPUT > OUTPUT.clean +test_expect_equal_file EXPECTED.common OUTPUT.clean + +test_begin_subtest "open/error: config=empty with no mail root in db (xdg)" +old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG} +unset NOTMUCH_CONFIG +backup_database +mkdir -p home/.local/share/notmuch +mv mail/.notmuch home/.local/share/notmuch/default +cat c_head3 c_body c_tail3 | test_C +restore_database +export NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +notmuch_dir_sanitize < OUTPUT > OUTPUT.clean +test_expect_equal_file EXPECTED.common OUTPUT.clean + test_done