]> git.notmuchmail.org Git - notmuch/blob - test/T030-config.sh
Merge tag '0.33.2'
[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.sexpr_query=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 "Top level --config=FILE option"
71 cp "${NOTMUCH_CONFIG}" alt-config
72 notmuch --config=alt-config config set user.name "Another Name"
73 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
74     "Another Name"
75
76 test_begin_subtest "Top level --config:FILE option"
77 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
78     "Another Name"
79
80 test_begin_subtest "Top level --config<space>FILE option"
81 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
82     "Another Name"
83
84 test_begin_subtest "Top level --config=FILE option changed the right file"
85 test_expect_equal "$(notmuch config get user.name)" \
86     "Notmuch Test Suite"
87
88 test_begin_subtest "Read config file through a symlink"
89 ln -s alt-config alt-config-link
90 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
91     "Another Name"
92
93 test_begin_subtest "Write config file through a symlink"
94 notmuch --config=alt-config-link config set user.name "Link Name"
95 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
96     "Link Name"
97
98 test_begin_subtest "Writing config file through symlink follows symlink"
99 test_expect_equal "$(readlink alt-config-link)" "alt-config"
100
101 test_begin_subtest "Round trip arbitrary key"
102 key=g${RANDOM}.m${RANDOM}
103 value=${RANDOM}
104 notmuch config set ${key} ${value}
105 output=$(notmuch config get ${key})
106 test_expect_equal "${output}" "${value}"
107
108 test_begin_subtest "Clear arbitrary key"
109 notmuch config set ${key}
110 output=$(notmuch config get ${key})
111 test_expect_equal "${output}" ""
112
113 db_path=${HOME}/database-path
114
115 test_begin_subtest "Absolute database path returned"
116 notmuch config set database.path ${HOME}/Maildir
117 test_expect_equal "$(notmuch config get database.path)" \
118                   "${HOME}/Maildir"
119
120 ln -s `pwd`/mail home/Maildir
121 add_email_corpus
122 test_begin_subtest "Relative database path expanded"
123 notmuch config set database.path Maildir
124 path=$(notmuch config get database.path | notmuch_dir_sanitize)
125 count=$(notmuch count '*')
126 test_expect_equal "${path} ${count}" \
127                   "CWD/home/Maildir 52"
128
129 test_begin_subtest "Add config to database"
130 notmuch new
131 key=g${RANDOM}.m${RANDOM}
132 value=${RANDOM}
133 notmuch config set --database ${key} ${value}
134 notmuch dump --include=config > OUTPUT
135 cat <<EOF > EXPECTED
136 #notmuch-dump batch-tag:3 config
137 #@ ${key} ${value}
138 EOF
139 test_expect_equal_file EXPECTED OUTPUT
140
141 test_begin_subtest "Roundtrip config to/from database"
142 notmuch new
143 key=g${RANDOM}.m${RANDOM}
144 value=${RANDOM}
145 notmuch config set --database ${key} ${value}
146 output=$(notmuch config get ${key})
147 test_expect_equal "${output}" "${value}"
148
149 test_begin_subtest "set built_with.* yields error"
150 test_expect_code 1 "notmuch config set built_with.compact false"
151
152 test_begin_subtest "get built_with.{compact,field_processor} prints true"
153 for key in compact field_processor; do
154     notmuch config get built_with.${key}
155 done > OUTPUT
156 cat <<EOF > EXPECTED
157 true
158 true
159 EOF
160 test_expect_equal_file EXPECTED OUTPUT
161
162 test_begin_subtest "get built_with.nonexistent prints false"
163 output=$(notmuch config get built_with.nonexistent)
164 test_expect_equal "$output" "false"
165
166 test_done