]> git.notmuchmail.org Git - notmuch/blob - test/T030-config.sh
lib/database: delete stemmer on destroy
[notmuch] / test / T030-config.sh
1 #!/usr/bin/env bash
2
3 test_description='"notmuch config"'
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 test_begin_subtest "Get string value"
7 test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
8
9 test_begin_subtest "Get list value"
10 cat <<EOF > EXPECTED
11 inbox
12 unread
13 EOF
14 notmuch config get new.tags | sort > OUTPUT
15 test_expect_equal_file EXPECTED OUTPUT
16
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"
20
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"
24
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)" "\
28 this
29 is a
30 list value"
31
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)" "\
35 this
36 is another
37 list value"
38
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)" ""
43
44 test_begin_subtest "Remove non-existent key"
45 notmuch config set foo.nonexistent
46 test_expect_equal "$(notmuch config get foo.nonexistent)" ""
47
48 test_begin_subtest "List all items"
49 notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
50 cat <<EOF > EXPECTED
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
60 maildir.synchronize_flags=true
61 new.ignore=
62 new.tags=unread;inbox
63 search.exclude_tags=
64 user.name=Notmuch Test Suite
65 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
66 user.primary_email=test_suite@notmuchmail.org
67 EOF
68 test_expect_equal_file EXPECTED OUTPUT
69
70 test_begin_subtest "Round trip config item with leading spaces"
71 test_subtest_known_broken
72 notmuch config set foo.bar "  thing"
73 output=$(notmuch config get foo.bar)
74 test_expect_equal "${output}" "  thing"
75
76 test_begin_subtest "Round trip config item with leading tab"
77 test_subtest_known_broken
78 notmuch config set foo.bar "    thing"
79 output=$(notmuch config get foo.bar)
80 test_expect_equal "${output}" " thing"
81
82 test_begin_subtest "Round trip config item with embedded tab"
83 notmuch config set foo.bar "thing       other"
84 output=$(notmuch config get foo.bar)
85 test_expect_equal "${output}" "thing    other"
86
87 test_begin_subtest "Round trip config item with embedded backslash"
88 notmuch config set foo.bar 'thing\other'
89 output=$(notmuch config get foo.bar)
90 test_expect_equal "${output}" "thing\other"
91
92 test_begin_subtest "Round trip config item with embedded NL/CR"
93 notmuch config set foo.bar 'thing
94 \rother'
95 output=$(notmuch config get foo.bar)
96 test_expect_equal "${output}" "thing
97 \rother"
98
99 test_begin_subtest "Top level --config=FILE option"
100 cp "${NOTMUCH_CONFIG}" alt-config
101 notmuch --config=alt-config config set user.name "Another Name"
102 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
103     "Another Name"
104
105 test_begin_subtest "Top level --config:FILE option"
106 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
107     "Another Name"
108
109 test_begin_subtest "Top level --config<space>FILE option"
110 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
111     "Another Name"
112
113 test_begin_subtest "Top level --config=FILE option changed the right file"
114 test_expect_equal "$(notmuch config get user.name)" \
115     "Notmuch Test Suite"
116
117 test_begin_subtest "Read config file through a symlink"
118 ln -s alt-config alt-config-link
119 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
120     "Another Name"
121
122 test_begin_subtest "Write config file through a symlink"
123 notmuch --config=alt-config-link config set user.name "Link Name"
124 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
125     "Link Name"
126
127 test_begin_subtest "Writing config file through symlink follows symlink"
128 test_expect_equal "$(readlink alt-config-link)" "alt-config"
129
130 test_begin_subtest "Round trip arbitrary key"
131 key=g${RANDOM}.m${RANDOM}
132 value=${RANDOM}
133 notmuch config set ${key} ${value}
134 output=$(notmuch config get ${key})
135 test_expect_equal "${output}" "${value}"
136
137 test_begin_subtest "Clear arbitrary key"
138 notmuch config set ${key}
139 output=$(notmuch config get ${key})
140 test_expect_equal "${output}" ""
141
142 db_path=${HOME}/database-path
143
144 test_begin_subtest "Absolute database path returned"
145 notmuch config set database.path ${HOME}/Maildir
146 test_expect_equal "$(notmuch config get database.path)" \
147                   "${HOME}/Maildir"
148
149 ln -s `pwd`/mail home/Maildir
150 add_email_corpus
151 test_begin_subtest "Relative database path expanded"
152 notmuch config set database.path Maildir
153 path=$(notmuch config get database.path | notmuch_dir_sanitize)
154 count=$(notmuch count '*')
155 test_expect_equal "${path} ${count}" \
156                   "CWD/home/Maildir 52"
157
158 test_begin_subtest "Add config to database"
159 notmuch new
160 key=g${RANDOM}.m${RANDOM}
161 value=${RANDOM}
162 notmuch config set --database ${key} ${value}
163 notmuch dump --include=config > OUTPUT
164 cat <<EOF > EXPECTED
165 #notmuch-dump batch-tag:3 config
166 #@ ${key} ${value}
167 EOF
168 test_expect_equal_file EXPECTED OUTPUT
169
170 test_begin_subtest "Roundtrip config to/from database"
171 notmuch new
172 key=g${RANDOM}.m${RANDOM}
173 value=${RANDOM}
174 notmuch config set --database ${key} ${value}
175 output=$(notmuch config get ${key})
176 test_expect_equal "${output}" "${value}"
177
178 test_begin_subtest "set built_with.* yields error"
179 test_expect_code 1 "notmuch config set built_with.compact false"
180
181 test_begin_subtest "get built_with.{compact,field_processor} prints true"
182 for key in compact field_processor; do
183     notmuch config get built_with.${key}
184 done > OUTPUT
185 cat <<EOF > EXPECTED
186 true
187 true
188 EOF
189 test_expect_equal_file EXPECTED OUTPUT
190
191 test_begin_subtest "get built_with.nonexistent prints false"
192 output=$(notmuch config get built_with.nonexistent)
193 test_expect_equal "$output" "false"
194
195 test_done