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
60 maildir.synchronize_flags=true
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
68 test_expect_equal_file EXPECTED OUTPUT
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"
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"
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"
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"
92 test_begin_subtest "Round trip config item with embedded NL/CR"
93 notmuch config set foo.bar 'thing
95 output=$(notmuch config get foo.bar)
96 test_expect_equal "${output}" "thing
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)" \
105 test_begin_subtest "Top level --config:FILE option"
106 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
109 test_begin_subtest "Top level --config<space>FILE option"
110 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
113 test_begin_subtest "Top level --config=FILE option changed the right file"
114 test_expect_equal "$(notmuch config get user.name)" \
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)" \
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)" \
127 test_begin_subtest "Writing config file through symlink follows symlink"
128 test_expect_equal "$(readlink alt-config-link)" "alt-config"
130 test_begin_subtest "Round trip arbitrary key"
131 key=g${RANDOM}.m${RANDOM}
133 notmuch config set ${key} ${value}
134 output=$(notmuch config get ${key})
135 test_expect_equal "${output}" "${value}"
137 test_begin_subtest "Clear arbitrary key"
138 notmuch config set ${key}
139 output=$(notmuch config get ${key})
140 test_expect_equal "${output}" ""
142 db_path=${HOME}/database-path
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)" \
149 ln -s `pwd`/mail home/Maildir
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"
158 test_begin_subtest "Add config to database"
160 key=g${RANDOM}.m${RANDOM}
162 notmuch config set --database ${key} ${value}
163 notmuch dump --include=config > OUTPUT
165 #notmuch-dump batch-tag:3 config
168 test_expect_equal_file EXPECTED OUTPUT
170 test_begin_subtest "Roundtrip config to/from database"
172 key=g${RANDOM}.m${RANDOM}
174 notmuch config set --database ${key} ${value}
175 output=$(notmuch config get ${key})
176 test_expect_equal "${output}" "${value}"
178 test_begin_subtest "set built_with.* yields error"
179 test_expect_code 1 "notmuch config set built_with.compact false"
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}
189 test_expect_equal_file EXPECTED OUTPUT
191 test_begin_subtest "get built_with.nonexistent prints false"
192 output=$(notmuch config get built_with.nonexistent)
193 test_expect_equal "$output" "false"