]> git.notmuchmail.org Git - notmuch/blob - test/T030-config.sh
CLI/config: use merged config for "config get"
[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 > STDOUT 2> STDERR
50 printf "%s\n====\n%s\n" "$(< STDOUT)" "$(< STDERR)" | notmuch_config_sanitize > OUTPUT
51
52 cat <<EOF > EXPECTED
53 database.path=MAIL_DIR
54 user.name=Notmuch Test Suite
55 user.primary_email=test_suite@notmuchmail.org
56 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
57 new.tags=unread;inbox;
58 new.ignore=
59 search.exclude_tags=
60 maildir.synchronize_flags=true
61 foo.string=this is another string value
62 foo.list=this;is another;list value;
63 built_with.compact=something
64 built_with.field_processor=something
65 built_with.retry_lock=something
66 ====
67 Error: Cannot open database at MAIL_DIR/.notmuch: No such file or directory.
68 EOF
69 test_expect_equal_file EXPECTED OUTPUT
70
71 test_begin_subtest "Top level --config=FILE option"
72 cp "${NOTMUCH_CONFIG}" alt-config
73 notmuch --config=alt-config config set user.name "Another Name"
74 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
75     "Another Name"
76
77 test_begin_subtest "Top level --config:FILE option"
78 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
79     "Another Name"
80
81 test_begin_subtest "Top level --config<space>FILE option"
82 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
83     "Another Name"
84
85 test_begin_subtest "Top level --config=FILE option changed the right file"
86 test_expect_equal "$(notmuch config get user.name)" \
87     "Notmuch Test Suite"
88
89 test_begin_subtest "Read config file through a symlink"
90 ln -s alt-config alt-config-link
91 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
92     "Another Name"
93
94 test_begin_subtest "Write config file through a symlink"
95 notmuch --config=alt-config-link config set user.name "Link Name"
96 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
97     "Link Name"
98
99 test_begin_subtest "Writing config file through symlink follows symlink"
100 test_expect_equal "$(readlink alt-config-link)" "alt-config"
101
102 test_begin_subtest "Round trip arbitrary key"
103 key=g${RANDOM}.m${RANDOM}
104 value=${RANDOM}
105 notmuch config set ${key} ${value}
106 output=$(notmuch config get ${key})
107 test_expect_equal "${output}" "${value}"
108
109 test_begin_subtest "Clear arbitrary key"
110 notmuch config set ${key}
111 output=$(notmuch config get ${key})
112 test_expect_equal "${output}" ""
113
114 db_path=${HOME}/database-path
115
116 test_begin_subtest "Absolute database path returned"
117 notmuch config set database.path ${HOME}/Maildir
118 test_expect_equal "$(notmuch config get database.path)" \
119                   "${HOME}/Maildir"
120
121 ln -s `pwd`/mail home/Maildir
122 add_email_corpus
123 test_begin_subtest "Relative database path expanded in open"
124 notmuch config set database.path Maildir
125 path=$(notmuch config get database.path)
126 count=$(notmuch count '*')
127 test_expect_equal "${path} ${count}" \
128                   "Maildir 52"
129
130 test_done