]> git.notmuchmail.org Git - notmuch/blob - test/T030-config.sh
test: known broken tests for escape characters in config files.
[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 test_subtest_known_broken
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 test_subtest_known_broken
95 notmuch config set foo.bar 'thing
96 \rother'
97 output=$(notmuch config get foo.bar)
98 test_expect_equal "${output}" "thing
99 \rother"
100
101 test_begin_subtest "Top level --config=FILE option"
102 cp "${NOTMUCH_CONFIG}" alt-config
103 notmuch --config=alt-config config set user.name "Another Name"
104 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
105     "Another Name"
106
107 test_begin_subtest "Top level --config:FILE option"
108 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
109     "Another Name"
110
111 test_begin_subtest "Top level --config<space>FILE option"
112 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
113     "Another Name"
114
115 test_begin_subtest "Top level --config=FILE option changed the right file"
116 test_expect_equal "$(notmuch config get user.name)" \
117     "Notmuch Test Suite"
118
119 test_begin_subtest "Read config file through a symlink"
120 ln -s alt-config alt-config-link
121 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
122     "Another Name"
123
124 test_begin_subtest "Write config file through a symlink"
125 notmuch --config=alt-config-link config set user.name "Link Name"
126 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
127     "Link Name"
128
129 test_begin_subtest "Writing config file through symlink follows symlink"
130 test_expect_equal "$(readlink alt-config-link)" "alt-config"
131
132 test_begin_subtest "Round trip arbitrary key"
133 key=g${RANDOM}.m${RANDOM}
134 value=${RANDOM}
135 notmuch config set ${key} ${value}
136 output=$(notmuch config get ${key})
137 test_expect_equal "${output}" "${value}"
138
139 test_begin_subtest "Clear arbitrary key"
140 notmuch config set ${key}
141 output=$(notmuch config get ${key})
142 test_expect_equal "${output}" ""
143
144 db_path=${HOME}/database-path
145
146 test_begin_subtest "Absolute database path returned"
147 notmuch config set database.path ${HOME}/Maildir
148 test_expect_equal "$(notmuch config get database.path)" \
149                   "${HOME}/Maildir"
150
151 ln -s `pwd`/mail home/Maildir
152 add_email_corpus
153 test_begin_subtest "Relative database path expanded"
154 notmuch config set database.path Maildir
155 path=$(notmuch config get database.path | notmuch_dir_sanitize)
156 count=$(notmuch count '*')
157 test_expect_equal "${path} ${count}" \
158                   "CWD/home/Maildir 52"
159
160 test_begin_subtest "Add config to database"
161 notmuch new
162 key=g${RANDOM}.m${RANDOM}
163 value=${RANDOM}
164 notmuch config set --database ${key} ${value}
165 notmuch dump --include=config > OUTPUT
166 cat <<EOF > EXPECTED
167 #notmuch-dump batch-tag:3 config
168 #@ ${key} ${value}
169 EOF
170 test_expect_equal_file EXPECTED OUTPUT
171
172 test_begin_subtest "Roundtrip config to/from database"
173 notmuch new
174 key=g${RANDOM}.m${RANDOM}
175 value=${RANDOM}
176 notmuch config set --database ${key} ${value}
177 output=$(notmuch config get ${key})
178 test_expect_equal "${output}" "${value}"
179
180 test_begin_subtest "set built_with.* yields error"
181 test_expect_code 1 "notmuch config set built_with.compact false"
182
183 test_begin_subtest "get built_with.{compact,field_processor} prints true"
184 for key in compact field_processor; do
185     notmuch config get built_with.${key}
186 done > OUTPUT
187 cat <<EOF > EXPECTED
188 true
189 true
190 EOF
191 test_expect_equal_file EXPECTED OUTPUT
192
193 test_begin_subtest "get built_with.nonexistent prints false"
194 output=$(notmuch config get built_with.nonexistent)
195 test_expect_equal "$output" "false"
196
197 test_done