1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
|
#!/usr/bin/env bash
test_description='Various options for reading configuration'
. $(dirname "$0")/test-lib.sh || exit 1
backup_config () {
local test_name=$(basename $0 .sh)
cp ${NOTMUCH_CONFIG} notmuch-config-backup.${test_name}
}
xdg_config () {
local dir
local profile=${1:-default}
if [[ $profile != default ]]; then
export NOTMUCH_PROFILE=$profile
fi
backup_config
dir="${HOME}/.config/notmuch/${profile}"
rm -rf $dir
mkdir -p $dir
CONFIG_PATH=$dir/config
mv ${NOTMUCH_CONFIG} ${CONFIG_PATH}
unset NOTMUCH_CONFIG
}
restore_config () {
local test_name=$(basename $0 .sh)
export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
unset CONFIG_PATH
unset NOTMUCH_PROFILE
cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
}
add_email_corpus
test_begin_subtest "count with saved query from config file"
backup_config
query_name="test${RANDOM}"
notmuch count query:$query_name > OUTPUT
printf "\n[query]\n${query_name} = tag:inbox\n" >> notmuch-config
notmuch count query:$query_name >> OUTPUT
cat <<EOF > EXPECTED
0
52
EOF
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "count with saved query from config file (xdg)"
query_name="test${RANDOM}"
xdg_config
notmuch count query:$query_name > OUTPUT
printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
notmuch count query:$query_name >> OUTPUT
cat <<EOF > EXPECTED
0
52
EOF
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "count with saved query from config file (xdg+profile)"
query_name="test${RANDOM}"
xdg_config work
notmuch count query:$query_name > OUTPUT
printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
notmuch count query:$query_name >> OUTPUT
cat <<EOF > EXPECTED
0
52
EOF
restore_config
test_expect_equal_file EXPECTED OUTPUT
cat <<EOF > EXPECTED
Before:
#notmuch-dump batch-tag:3 tags
After:
#notmuch-dump batch-tag:3 tags
+attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
+attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
+inbox +signed +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
+inbox +signed +unread -- id:20091117203301.GV3165@dottiness.seas.harvard.edu
+inbox +signed +unread -- id:20091118002059.067214ed@hikari
+inbox +signed +unread -- id:20091118005040.GA25380@dottiness.seas.harvard.edu
+inbox +signed +unread -- id:87iqd9rn3l.fsf@vertex.dottedmag
EOF
test_begin_subtest "dump with saved query from config file"
backup_config
query_name="test${RANDOM}"
CONFIG_PATH=notmuch-config
printf "Before:\n" > OUTPUT
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
printf "\nAfter:\n" >> OUTPUT
printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "dump with saved query from config file (xdg)"
backup_config
query_name="test${RANDOM}"
xdg_config
printf "Before:\n" > OUTPUT
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
printf "\nAfter:\n" >> OUTPUT
printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "dump with saved query from config file (xdg+profile)"
backup_config
query_name="test${RANDOM}"
xdg_config work
printf "Before:\n" > OUTPUT
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
printf "\nAfter:\n" >> OUTPUT
printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "restore with xdg config"
backup_config
notmuch dump '*' > EXPECTED
notmuch tag -inbox '*'
xdg_config
notmuch restore --input=EXPECTED
notmuch dump > OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "restore with xdg+profile config"
backup_config
notmuch dump '*' > EXPECTED
notmuch tag -inbox '*'
xdg_config work
notmuch restore --input=EXPECTED
notmuch dump > OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "Insert message with custom new.tags (xdg)"
backup_config
xdg_config
tag=test${RANDOM}
notmuch --config=${CONFIG_PATH} config set new.tags $tag
generate_message \
"[subject]=\"insert-subject\"" \
"[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
"[body]=\"insert-message\""
mkdir -p ${MAIL_DIR}/{cur,new,tmp}
notmuch insert < "$gen_msg_filename"
notmuch dump id:$gen_msg_id > OUTPUT
cat <<EOF > EXPECTED
#notmuch-dump batch-tag:3 config,properties,tags
+$tag -- id:$gen_msg_id
EOF
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "Insert message with custom new.tags (xdg+profile)"
backup_config
tag=test${RANDOM}
xdg_config $tag
notmuch --config=${CONFIG_PATH} config set new.tags $tag
generate_message \
"[subject]=\"insert-subject\"" \
"[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
"[body]=\"insert-message\""
mkdir -p ${MAIL_DIR}/{cur,new,tmp}
notmuch insert < "$gen_msg_filename"
notmuch dump id:$gen_msg_id > OUTPUT
cat <<EOF > EXPECTED
#notmuch-dump batch-tag:3 config,properties,tags
+$tag -- id:$gen_msg_id
EOF
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "reindex with saved query from config file"
backup_config
query_name="test${RANDOM}"
count1=$(notmuch count --lastmod '*' | cut -f3)
printf "\n[query]\n${query_name} = tag:inbox\n" >> notmuch-config
notmuch reindex query:$query_name
count2=$(notmuch count --lastmod '*' | cut -f3)
restore_config
test_expect_success "test '$count2 -gt $count1'"
test_begin_subtest "reindex with saved query from config file (xdg)"
query_name="test${RANDOM}"
count1=$(notmuch count --lastmod '*' | cut -f3)
xdg_config
printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
notmuch reindex query:$query_name
count2=$(notmuch count --lastmod '*' | cut -f3)
restore_config
test_expect_success "test '$count2 -gt $count1'"
test_begin_subtest "reindex with saved query from config file (xdg+profile)"
query_name="test${RANDOM}"
count1=$(notmuch count --lastmod '*' | cut -f3)
xdg_config $query_name
printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
notmuch reindex query:$query_name
count2=$(notmuch count --lastmod '*' | cut -f3)
restore_config
test_expect_success "test '$count2 -gt $count1'"
add_message '[from]="Sender <sender@example.com>"' \
[to]=test_suite@notmuchmail.org \
'[cc]="Other Parties <cc@example.com>"' \
[subject]=notmuch-reply-test \
'[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
'[body]="reply with CC"'
cat <<EOF > EXPECTED
Before:
After:
From: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: Re: notmuch-reply-test
To: Sender <sender@example.com>
Cc: Other Parties <cc@example.com>
In-Reply-To: <${gen_msg_id}>
References: <${gen_msg_id}>
On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
> reply with CC
EOF
test_begin_subtest "reply with saved query from config file"
backup_config
query_name="test${RANDOM}"
printf "Before:\n" > OUTPUT
notmuch reply query:$query_name 2>&1 >> OUTPUT
printf "\n[query]\n${query_name} = id:${gen_msg_id}\n" >> notmuch-config
printf "After:\n" >> OUTPUT
notmuch reply query:$query_name >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "reply with saved query from config file (xdg)"
backup_config
query_name="test${RANDOM}"
xdg_config
printf "Before:\n" > OUTPUT
notmuch reply query:$query_name 2>&1 >> OUTPUT
printf "\n[query]\n${query_name} = id:${gen_msg_id}\n" >> ${CONFIG_PATH}
printf "After:\n" >> OUTPUT
notmuch reply query:$query_name >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "reply with saved query from config file (xdg+profile)"
backup_config
query_name="test${RANDOM}"
xdg_config $query_name
printf "Before:\n" > OUTPUT
notmuch reply query:$query_name 2>&1 >> OUTPUT
printf "\n[query]\n${query_name} = id:${gen_msg_id}\n" >> ${CONFIG_PATH}
printf "After:\n" >> OUTPUT
notmuch reply query:$query_name >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
backup_database
test_begin_subtest "search with alternate config"
notmuch tag -- +foobar17 '*'
cp notmuch-config alt-config
notmuch --config=alt-config config set search.exclude_tags foobar17
output=$(notmuch --config=alt-config count '*')
test_expect_equal "$output" "0"
restore_database
cat <<EOF > EXPECTED
Before:
After:
thread:XXX 2009-11-18 [1/2] Carl Worth| Alex Botero-Lowry; [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread)
thread:XXX 2009-11-18 [1/2] Carl Worth| Ingmar Vanhassel; [notmuch] [PATCH] Typsos (inbox unread)
thread:XXX 2009-11-18 [1/3] Carl Worth| Adrian Perez de Castro, Keith Packard; [notmuch] Introducing myself (inbox signed unread)
thread:XXX 2009-11-18 [1/3] Carl Worth| Israel Herraiz, Keith Packard; [notmuch] New to the list (inbox unread)
thread:XXX 2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
thread:XXX 2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
thread:XXX 2009-11-18 [1/3(4)] Carl Worth| Aron Griffis, Keith Packard; [notmuch] archive (inbox unread)
thread:XXX 2009-11-18 [1/2] Carl Worth| Keith Packard; [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)
thread:XXX 2009-11-18 [1/7] Carl Worth| Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard; [notmuch] Working with Maildir storage? (inbox signed unread)
thread:XXX 2009-11-18 [2/5] Carl Worth| Mikhail Gusarov, Keith Packard; [notmuch] [PATCH 1/2] Close message file after parsing message headers (inbox unread)
thread:XXX 2009-11-17 [1/2] Carl Worth| Alex Botero-Lowry; [notmuch] preliminary FreeBSD support (attachment inbox unread)
EOF
test_begin_subtest "search with saved query from config file"
query_name="test${RANDOM}"
backup_config
printf "Before:\n" > OUTPUT
notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
printf "\n[query]\n${query_name} = from:cworth\n" >> notmuch-config
printf "After:\n" >> OUTPUT
notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "search with saved query from config file (xdg)"
query_name="test${RANDOM}"
xdg_config
printf "Before:\n" > OUTPUT
notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
printf "\n[query]\n${query_name} = from:cworth\n" >> ${CONFIG_PATH}
printf "After:\n" >> OUTPUT
notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "search with saved query from config file (xdg + profile)"
query_name="test${RANDOM}"
xdg_config $query_name
printf "Before:\n" > OUTPUT
notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
printf "\n[query]\n${query_name} = from:cworth\n" >> ${CONFIG_PATH}
printf "After:\n" >> OUTPUT
notmuch search query:$query_name 2>&1 | notmuch_search_sanitize >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
cat <<EOF > EXPECTED
Before:
After:
Alex Botero-Lowry <alex.boterolowry@gmail.com>
Alexander Botero-Lowry <alex.boterolowry@gmail.com>
François Boulogne <boulogne.f@gmail.com>
Jjgod Jiang <gzjjgod@gmail.com>
EOF
test_begin_subtest "address: saved query from config file"
backup_config
query_name="test${RANDOM}"
printf "Before:\n" > OUTPUT
notmuch address --deduplicate=no --output=sender query:$query_name 2>&1 | sort >> OUTPUT
printf "\n[query]\n${query_name} = from:gmail.com\n" >> notmuch-config
printf "After:\n" >> OUTPUT
notmuch address --output=sender query:$query_name | sort >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "address: saved query from config file (xdg)"
query_name="test${RANDOM}"
xdg_config
printf "Before:\n" > OUTPUT
notmuch address --deduplicate=no --output=sender query:$query_name 2>&1 | sort >> OUTPUT
printf "\n[query]\n${query_name} = from:gmail.com\n" >> ${CONFIG_PATH}
printf "After:\n" >> OUTPUT
notmuch address --output=sender query:$query_name | sort >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "address: saved query from config file (xdg+profile)"
query_name="test${RANDOM}"
xdg_config $query_name
printf "Before:\n" > OUTPUT
notmuch address --deduplicate=no --output=sender query:$query_name 2>&1 | sort >> OUTPUT
printf "\n[query]\n${query_name} = from:gmail.com\n" >> ${CONFIG_PATH}
printf "After:\n" >> OUTPUT
notmuch address --output=sender query:$query_name | sort >> OUTPUT
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "show with alternate config"
backup_database
cp notmuch-config alt-config
notmuch --config=alt-config config set search.exclude_tags foobar17
notmuch tag -- +foobar17 '*'
output=$(notmuch --config=alt-config show '*' && echo OK)
restore_database
test_expect_equal "$output" "OK"
test_begin_subtest "show with alternate config (xdg)"
backup_database
notmuch tag -- +foobar17 '*'
xdg_config
notmuch --config=${CONFIG_PATH} config set search.exclude_tags foobar17
output=$(notmuch show '*' && echo OK)
restore_database
restore_config
test_expect_equal "$output" "OK"
test_begin_subtest "show with alternate config (xdg+profile)"
backup_database
notmuch tag -- +foobar17 '*'
xdg_config foobar17
notmuch --config=${CONFIG_PATH} config set search.exclude_tags foobar17
output=$(notmuch show '*' && echo OK)
restore_database
restore_config
test_expect_equal "$output" "OK"
# reset to known state
add_email_corpus
test_begin_subtest "tag with saved query from config file"
backup_config
query_name="test${RANDOM}"
tag_name="tag${RANDOM}"
notmuch count query:$query_name > OUTPUT
printf "\n[query]\n${query_name} = tag:inbox\n" >> notmuch-config
notmuch tag +$tag_name -- query:${query_name}
notmuch count tag:$tag_name >> OUTPUT
cat <<EOF > EXPECTED
0
52
EOF
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "tag with saved query from config file (xdg)"
xdg_config
query_name="test${RANDOM}"
tag_name="tag${RANDOM}"
notmuch count query:$query_name > OUTPUT
printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
notmuch tag +$tag_name -- query:${query_name}
notmuch count tag:$tag_name >> OUTPUT
cat <<EOF > EXPECTED
0
52
EOF
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "tag with saved query from config file (xdg+profile)"
query_name="test${RANDOM}"
xdg_config ${query_name}
tag_name="tag${RANDOM}"
notmuch count query:$query_name > OUTPUT
printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
notmuch tag +$tag_name -- query:${query_name}
notmuch count tag:$tag_name >> OUTPUT
cat <<EOF > EXPECTED
0
52
EOF
restore_config
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "running compact (xdg)"
xdg_config
notmuch compact
output=$(notmuch count '*')
restore_config
test_expect_equal "52" "$output"
test_begin_subtest "running compact (xdg + profile)"
xdg_config ${RANDOM}
notmuch compact
output=$(notmuch count '*')
restore_config
test_expect_equal "52" "$output"
test_begin_subtest "run notmuch-new (xdg)"
xdg_config
generate_message
output=$(NOTMUCH_NEW --debug)
restore_config
test_expect_equal "$output" "Added 1 new message to the database."
test_begin_subtest "run notmuch-new (xdg + profile)"
xdg_config ${RANDOM}
generate_message
output=$(NOTMUCH_NEW --debug)
restore_config
test_expect_equal "$output" "Added 1 new message to the database."
test_done
|