3 test_description='"notmuch config"'
4 . $(dirname "$0")/test-lib.sh || exit 1
6 cp notmuch-config initial-config
8 test_begin_subtest "Get string value"
9 test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
11 test_begin_subtest "Get list value"
16 notmuch config get new.tags | sort > OUTPUT
17 test_expect_equal_file EXPECTED OUTPUT
19 test_begin_subtest "Set string value"
20 notmuch config set foo.string "this is a string value"
21 test_expect_equal "$(notmuch config get foo.string)" "this is a string value"
23 test_begin_subtest "Set string value again"
24 notmuch config set foo.string "this is another string value"
25 test_expect_equal "$(notmuch config get foo.string)" "this is another string value"
27 test_begin_subtest "Set list value"
28 notmuch config set foo.list this "is a" "list value"
29 test_expect_equal "$(notmuch config get foo.list)" "\
34 test_begin_subtest "Set list value again"
35 notmuch config set foo.list this "is another" "list value"
36 test_expect_equal "$(notmuch config get foo.list)" "\
41 test_begin_subtest "Remove key"
42 notmuch config set foo.remove baz
43 notmuch config set foo.remove
44 test_expect_equal "$(notmuch config get foo.remove)" ""
46 test_begin_subtest "Remove non-existent key"
47 notmuch config set foo.nonexistent
48 test_expect_equal "$(notmuch config get foo.nonexistent)" ""
50 test_begin_subtest "List all items"
51 notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
53 built_with.compact=something
54 built_with.field_processor=something
55 built_with.retry_lock=something
56 built_with.sexp_queries=something
57 database.autocommit=8000
58 database.mail_root=MAIL_DIR
59 database.path=MAIL_DIR
60 foo.list=this;is another;list value;
61 foo.string=this is another string value
63 maildir.synchronize_flags=true
67 user.name=Notmuch Test Suite
68 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
69 user.primary_email=test_suite@notmuchmail.org
71 test_expect_equal_file EXPECTED OUTPUT
73 test_begin_subtest "Round trip config item with leading spaces"
74 test_subtest_known_broken
75 notmuch config set foo.bar " thing"
76 output=$(notmuch config get foo.bar)
77 test_expect_equal "${output}" " thing"
79 test_begin_subtest "Round trip config item with leading tab"
80 test_subtest_known_broken
81 notmuch config set foo.bar " thing"
82 output=$(notmuch config get foo.bar)
83 test_expect_equal "${output}" " thing"
85 test_begin_subtest "Round trip config item with embedded tab"
86 notmuch config set foo.bar "thing other"
87 output=$(notmuch config get foo.bar)
88 test_expect_equal "${output}" "thing other"
90 test_begin_subtest "Round trip config item with embedded backslash"
91 notmuch config set foo.bar 'thing\other'
92 output=$(notmuch config get foo.bar)
93 test_expect_equal "${output}" "thing\other"
95 test_begin_subtest "Round trip config item with embedded NL/CR"
96 notmuch config set foo.bar 'thing
98 output=$(notmuch config get foo.bar)
99 test_expect_equal "${output}" "thing
102 test_begin_subtest "Top level --config=FILE option"
103 cp "${NOTMUCH_CONFIG}" alt-config
104 notmuch --config=alt-config config set user.name "Another Name"
105 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
108 test_begin_subtest "Top level --config:FILE option"
109 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
112 test_begin_subtest "Top level --config<space>FILE option"
113 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
116 test_begin_subtest "Top level --config=FILE option changed the right file"
117 test_expect_equal "$(notmuch config get user.name)" \
120 test_begin_subtest "Read config file through a symlink"
121 ln -s alt-config alt-config-link
122 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
125 test_begin_subtest "Write config file through a symlink"
126 notmuch --config=alt-config-link config set user.name "Link Name"
127 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
130 test_begin_subtest "Writing config file through symlink follows symlink"
131 test_expect_equal "$(readlink alt-config-link)" "alt-config"
133 test_begin_subtest "Round trip arbitrary key"
134 key=g${RANDOM}.m${RANDOM}
136 notmuch config set ${key} ${value}
137 output=$(notmuch config get ${key})
138 test_expect_equal "${output}" "${value}"
140 test_begin_subtest "Clear arbitrary key"
141 notmuch config set ${key}
142 output=$(notmuch config get ${key})
143 test_expect_equal "${output}" ""
145 db_path=${HOME}/database-path
147 test_begin_subtest "Absolute database path returned"
148 notmuch config set database.path ${HOME}/Maildir
149 test_expect_equal "$(notmuch config get database.path)" \
152 ln -s `pwd`/mail home/Maildir
154 test_begin_subtest "Relative database path expanded"
155 notmuch config set database.path Maildir
156 path=$(notmuch config get database.path | notmuch_dir_sanitize)
157 count=$(notmuch count '*')
158 test_expect_equal "${path} ${count}" \
159 "CWD/home/Maildir 52"
161 test_begin_subtest "Add config to database"
163 key=g${RANDOM}.m${RANDOM}
165 notmuch config set --database ${key} ${value}
166 notmuch dump --include=config > OUTPUT
168 #notmuch-dump batch-tag:3 config
171 test_expect_equal_file EXPECTED OUTPUT
173 test_begin_subtest "Roundtrip config to/from database"
175 key=g${RANDOM}.m${RANDOM}
177 notmuch config set --database ${key} ${value}
178 output=$(notmuch config get ${key})
179 test_expect_equal "${output}" "${value}"
181 test_begin_subtest "set built_with.* yields error"
182 test_expect_code 1 "notmuch config set built_with.compact false"
184 test_begin_subtest "get built_with.{compact,field_processor} prints true"
185 for key in compact field_processor; do
186 notmuch config get built_with.${key}
192 test_expect_equal_file EXPECTED OUTPUT
194 test_begin_subtest "get built_with.nonexistent prints false"
195 output=$(notmuch config get built_with.nonexistent)
196 test_expect_equal "$output" "false"
198 test_begin_subtest "Bad utf8 reported as error"
199 cp initial-config bad-config
200 printf '[query]\nq3=from:\xff\n' >>bad-config
201 test_expect_code 1 "notmuch --config=./bad-config config list"
203 test_begin_subtest "Specific error message about bad utf8"
204 notmuch --config=./bad-config config list 2>ERRORS
206 GLib: Key file contains key “q3” with value “from:�” which is not UTF-8
207 Error: unable to load config file.
209 test_expect_equal_file EXPECTED ERRORS