3 test_description='"notmuch config"'
4 . $(dirname "$0")/test-lib.sh || exit 1
6 test_begin_subtest "Get string value"
7 test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
9 test_begin_subtest "Get list value"
14 notmuch config get new.tags | sort > OUTPUT
15 test_expect_equal_file EXPECTED OUTPUT
17 test_begin_subtest "Set string value"
18 notmuch config set foo.string "this is a string value"
19 test_expect_equal "$(notmuch config get foo.string)" "this is a string value"
21 test_begin_subtest "Set string value again"
22 notmuch config set foo.string "this is another string value"
23 test_expect_equal "$(notmuch config get foo.string)" "this is another string value"
25 test_begin_subtest "Set list value"
26 notmuch config set foo.list this "is a" "list value"
27 test_expect_equal "$(notmuch config get foo.list)" "\
32 test_begin_subtest "Set list value again"
33 notmuch config set foo.list this "is another" "list value"
34 test_expect_equal "$(notmuch config get foo.list)" "\
39 test_begin_subtest "Remove key"
40 notmuch config set foo.remove baz
41 notmuch config set foo.remove
42 test_expect_equal "$(notmuch config get foo.remove)" ""
44 test_begin_subtest "Remove non-existent key"
45 notmuch config set foo.nonexistent
46 test_expect_equal "$(notmuch config get foo.nonexistent)" ""
48 test_begin_subtest "List all items"
49 notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
51 built_with.compact=something
52 built_with.field_processor=something
53 built_with.retry_lock=something
54 built_with.sexp_queries=something
55 database.autocommit=8000
56 database.mail_root=MAIL_DIR
57 database.path=MAIL_DIR
58 foo.list=this;is another;list value;
59 foo.string=this is another string value
61 maildir.synchronize_flags=true
65 user.name=Notmuch Test Suite
66 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
67 user.primary_email=test_suite@notmuchmail.org
69 test_expect_equal_file EXPECTED OUTPUT
71 test_begin_subtest "Round trip config item with leading spaces"
72 test_subtest_known_broken
73 notmuch config set foo.bar " thing"
74 output=$(notmuch config get foo.bar)
75 test_expect_equal "${output}" " thing"
77 test_begin_subtest "Round trip config item with leading tab"
78 test_subtest_known_broken
79 notmuch config set foo.bar " thing"
80 output=$(notmuch config get foo.bar)
81 test_expect_equal "${output}" " thing"
83 test_begin_subtest "Round trip config item with embedded tab"
84 notmuch config set foo.bar "thing other"
85 output=$(notmuch config get foo.bar)
86 test_expect_equal "${output}" "thing other"
88 test_begin_subtest "Round trip config item with embedded backslash"
89 notmuch config set foo.bar 'thing\other'
90 output=$(notmuch config get foo.bar)
91 test_expect_equal "${output}" "thing\other"
93 test_begin_subtest "Round trip config item with embedded NL/CR"
94 notmuch config set foo.bar 'thing
96 output=$(notmuch config get foo.bar)
97 test_expect_equal "${output}" "thing
100 test_begin_subtest "Top level --config=FILE option"
101 cp "${NOTMUCH_CONFIG}" alt-config
102 notmuch --config=alt-config config set user.name "Another Name"
103 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
106 test_begin_subtest "Top level --config:FILE option"
107 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
110 test_begin_subtest "Top level --config<space>FILE option"
111 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
114 test_begin_subtest "Top level --config=FILE option changed the right file"
115 test_expect_equal "$(notmuch config get user.name)" \
118 test_begin_subtest "Read config file through a symlink"
119 ln -s alt-config alt-config-link
120 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
123 test_begin_subtest "Write config file through a symlink"
124 notmuch --config=alt-config-link config set user.name "Link Name"
125 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
128 test_begin_subtest "Writing config file through symlink follows symlink"
129 test_expect_equal "$(readlink alt-config-link)" "alt-config"
131 test_begin_subtest "Round trip arbitrary key"
132 key=g${RANDOM}.m${RANDOM}
134 notmuch config set ${key} ${value}
135 output=$(notmuch config get ${key})
136 test_expect_equal "${output}" "${value}"
138 test_begin_subtest "Clear arbitrary key"
139 notmuch config set ${key}
140 output=$(notmuch config get ${key})
141 test_expect_equal "${output}" ""
143 db_path=${HOME}/database-path
145 test_begin_subtest "Absolute database path returned"
146 notmuch config set database.path ${HOME}/Maildir
147 test_expect_equal "$(notmuch config get database.path)" \
150 ln -s `pwd`/mail home/Maildir
152 test_begin_subtest "Relative database path expanded"
153 notmuch config set database.path Maildir
154 path=$(notmuch config get database.path | notmuch_dir_sanitize)
155 count=$(notmuch count '*')
156 test_expect_equal "${path} ${count}" \
157 "CWD/home/Maildir 52"
159 test_begin_subtest "Add config to database"
161 key=g${RANDOM}.m${RANDOM}
163 notmuch config set --database ${key} ${value}
164 notmuch dump --include=config > OUTPUT
166 #notmuch-dump batch-tag:3 config
169 test_expect_equal_file EXPECTED OUTPUT
171 test_begin_subtest "Roundtrip config to/from database"
173 key=g${RANDOM}.m${RANDOM}
175 notmuch config set --database ${key} ${value}
176 output=$(notmuch config get ${key})
177 test_expect_equal "${output}" "${value}"
179 test_begin_subtest "set built_with.* yields error"
180 test_expect_code 1 "notmuch config set built_with.compact false"
182 test_begin_subtest "get built_with.{compact,field_processor} prints true"
183 for key in compact field_processor; do
184 notmuch config get built_with.${key}
190 test_expect_equal_file EXPECTED OUTPUT
192 test_begin_subtest "get built_with.nonexistent prints false"
193 output=$(notmuch config get built_with.nonexistent)
194 test_expect_equal "$output" "false"