]> git.notmuchmail.org Git - notmuch/blob - test/T030-config.sh
lib: add config key INDEX_AS_TEXT
[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 index.as_text=
61 maildir.synchronize_flags=true
62 new.ignore=
63 new.tags=unread;inbox
64 search.exclude_tags=
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
68 EOF
69 test_expect_equal_file EXPECTED OUTPUT
70
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"
76
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"
82
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"
87
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"
92
93 test_begin_subtest "Round trip config item with embedded NL/CR"
94 notmuch config set foo.bar 'thing
95 \rother'
96 output=$(notmuch config get foo.bar)
97 test_expect_equal "${output}" "thing
98 \rother"
99
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)" \
104     "Another Name"
105
106 test_begin_subtest "Top level --config:FILE option"
107 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
108     "Another Name"
109
110 test_begin_subtest "Top level --config<space>FILE option"
111 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
112     "Another Name"
113
114 test_begin_subtest "Top level --config=FILE option changed the right file"
115 test_expect_equal "$(notmuch config get user.name)" \
116     "Notmuch Test Suite"
117
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)" \
121     "Another Name"
122
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)" \
126     "Link Name"
127
128 test_begin_subtest "Writing config file through symlink follows symlink"
129 test_expect_equal "$(readlink alt-config-link)" "alt-config"
130
131 test_begin_subtest "Round trip arbitrary key"
132 key=g${RANDOM}.m${RANDOM}
133 value=${RANDOM}
134 notmuch config set ${key} ${value}
135 output=$(notmuch config get ${key})
136 test_expect_equal "${output}" "${value}"
137
138 test_begin_subtest "Clear arbitrary key"
139 notmuch config set ${key}
140 output=$(notmuch config get ${key})
141 test_expect_equal "${output}" ""
142
143 db_path=${HOME}/database-path
144
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)" \
148                   "${HOME}/Maildir"
149
150 ln -s `pwd`/mail home/Maildir
151 add_email_corpus
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"
158
159 test_begin_subtest "Add config to database"
160 notmuch new
161 key=g${RANDOM}.m${RANDOM}
162 value=${RANDOM}
163 notmuch config set --database ${key} ${value}
164 notmuch dump --include=config > OUTPUT
165 cat <<EOF > EXPECTED
166 #notmuch-dump batch-tag:3 config
167 #@ ${key} ${value}
168 EOF
169 test_expect_equal_file EXPECTED OUTPUT
170
171 test_begin_subtest "Roundtrip config to/from database"
172 notmuch new
173 key=g${RANDOM}.m${RANDOM}
174 value=${RANDOM}
175 notmuch config set --database ${key} ${value}
176 output=$(notmuch config get ${key})
177 test_expect_equal "${output}" "${value}"
178
179 test_begin_subtest "set built_with.* yields error"
180 test_expect_code 1 "notmuch config set built_with.compact false"
181
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}
185 done > OUTPUT
186 cat <<EOF > EXPECTED
187 true
188 true
189 EOF
190 test_expect_equal_file EXPECTED OUTPUT
191
192 test_begin_subtest "get built_with.nonexistent prints false"
193 output=$(notmuch config get built_with.nonexistent)
194 test_expect_equal "$output" "false"
195
196 test_done