]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test
test: Make existing "notmuch show" test more resilient
[notmuch] / test / notmuch-test
1 #!/bin/bash
2 set -e
3
4 find_notmuch_binary ()
5 {
6     dir=$1
7
8     while [ -n "$dir" ]; do
9         bin=$dir/notmuch
10         if [ -x $bin ]; then
11             echo $bin
12             return
13         fi
14         dir=$(dirname $dir)
15         if [ "$dir" = "/" ]; then
16             break
17         fi
18     done
19
20     echo notmuch
21 }
22
23 increment_mtime_amount=0
24 increment_mtime ()
25 {
26     dir=$1
27
28     increment_mtime_amount=$((increment_mtime_amount + 1))
29     touch -d "+${increment_mtime_amount} seconds" $dir
30 }
31
32 # Generate a new message in the mail directory, with a unique message
33 # ID and subject. The message is not added to the index.
34 #
35 # After this function returns, the filename of the generated message
36 # is available as $gen_msg_filename and the message ID is available as
37 # $gen_msg_id .
38 #
39 # This function supports named parameters with the bash syntax for
40 # assigning a value to an associative array ([name]=value). The
41 # supported parameters are:
42 #
43 #  [dir]=directory/of/choice
44 #
45 #       Generate the message in directory 'directory/of/choice' within
46 #       the mail store. The directory will be created if necessary.
47 #
48 #  [body]=text
49 #
50 #       Text to use as the body of the email message
51 #
52 #  '[from]="Some User <user@example.com>"'
53 #  '[to]="Some User <user@example.com>"'
54 #  '[subject]="Subject of email message"'
55 #  '[date]="RFC 822 Date"'
56 #
57 #       Values for email headers. If not provided, default values will
58 #       be generated instead.
59 #
60 #  '[cc]="Some User <user@example.com>"'
61 #  [reply-to]=some-address
62 #  [in-reply-to]=<message-id>
63 #
64 #       Additional values for email headers. If these are not provided
65 #       then the relevant headers will simply not appear in the
66 #       message.
67 #
68 #  '[id]=<message-id>'
69 #
70 #       Controls the message-id of the created message.
71 gen_msg_cnt=0
72 gen_msg_filename=""
73 gen_msg_id=""
74 generate_message ()
75 {
76     # This is our (bash-specific) magic for doing named parameters
77     local -A template="($@)"
78     local additional_headers
79
80     if [ -z "${template[id]}" ]; then
81         gen_msg_cnt=$((gen_msg_cnt + 1))
82         gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
83         gen_msg_id="${gen_msg_name}@notmuch-test-suite"
84     else
85         gen_msg_name="msg-${template[id]}"
86         gen_msg_id="${template[id]}"
87     fi
88
89     if [ -z "${template[dir]}" ]; then
90         gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
91     else
92         gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
93         mkdir -p $(dirname $gen_msg_filename)
94     fi
95
96     if [ -z "${template[body]}" ]; then
97         template[body]="This is just a test message (#${gen_msg_cnt})"
98     fi
99
100     if [ -z "${template[from]}" ]; then
101         template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
102     fi
103
104     if [ -z "${template[to]}" ]; then
105         template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
106     fi
107
108     if [ -z "${template[subject]}" ]; then
109         template[subject]="Test message #${gen_msg_cnt}"
110     fi
111
112     if [ -z "${template[date]}" ]; then
113         template[date]="Tue, 05 Jan 2001 15:43:57 -0800"
114     fi
115
116     additional_headers=""
117     if [ ! -z "${template[reply-to]}" ]; then
118         additional_headers="Reply-To: ${template[reply-to]}
119 ${additional_headers}"
120     fi
121
122     if [ ! -z "${template[in-reply-to]}" ]; then
123         additional_headers="In-Reply-To: ${template[in-reply-to]}
124 ${additional_headers}"
125     fi
126
127     if [ ! -z "${template[cc]}" ]; then
128         additional_headers="Cc: ${template[cc]}
129 ${additional_headers}"
130     fi
131
132 cat <<EOF >$gen_msg_filename
133 From: ${template[from]}
134 To: ${template[to]}
135 Message-Id: <${gen_msg_id}>
136 Subject: ${template[subject]}
137 Date: ${template[date]}
138 ${additional_headers}
139 ${template[body]}
140 EOF
141
142     # Ensure that the mtime of the containing directory is updated
143     increment_mtime $(dirname ${gen_msg_filename})
144 }
145
146 # Generate a new message and add it to the index.
147 #
148 # All of the arguments and return values supported by generate_message
149 # are also supported here, so see that function for details.
150 add_message ()
151 {
152     generate_message "$@"
153
154     $NOTMUCH new > /dev/null
155 }
156
157 tests=0
158 test_failures=0
159
160 pass_if_equal ()
161 {
162     output=$1
163     expected=$2
164
165     tests=$((tests + 1))
166
167     if [ "$output" = "$expected" ]; then
168         echo "  PASS"
169     else
170         echo "  FAIL"
171         testname=test-$(printf "%03d" $tests)
172         echo "$expected" > $testname.expected
173         echo "$output" > $testname.output
174         diff -u $testname.expected $testname.output || true
175         test_failures=$((test_failures + 1))
176     fi
177 }
178
179 TEST_DIR=$(pwd)/test.$$
180 MAIL_DIR=${TEST_DIR}/mail
181 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
182 NOTMUCH=$(find_notmuch_binary $(pwd))
183
184 NOTMUCH_NEW ()
185 {
186     $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
187 }
188
189 NOTMUCH_SEARCH_THREAD_ID_SQUELCH='s/thread:................/thread:XXX/'
190 notmuch_search_sanitize ()
191 {
192     sed -e "$NOTMUCH_SEARCH_THREAD_ID_SQUELCH"
193 }
194
195 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
196 notmuch_show_sanitize ()
197 {
198     sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
199 }
200
201 rm -rf ${TEST_DIR}
202 mkdir ${TEST_DIR}
203 cd ${TEST_DIR}
204
205 mkdir ${MAIL_DIR}
206
207 cat <<EOF > ${NOTMUCH_CONFIG}
208 [database]
209 path=${MAIL_DIR}
210
211 [user]
212 name=Notmuch Test Suite
213 primary_email=test_suite@notmuchmail.org
214 other_email=test_suite_other@notmuchmail.org
215 EOF
216
217 printf "Testing \"notmuch new\" in several variations:\n"
218 printf " No new messages...\t\t\t\t"
219 output=$(NOTMUCH_NEW)
220 pass_if_equal "$output" "No new mail."
221
222 printf " Single new message...\t\t\t\t"
223 generate_message
224 output=$(NOTMUCH_NEW)
225 pass_if_equal "$output" "Added 1 new message to the database."
226
227 printf " Multiple new messages...\t\t\t"
228 generate_message
229 generate_message
230 output=$(NOTMUCH_NEW)
231 pass_if_equal "$output" "Added 2 new messages to the database."
232
233 printf " No new messages (non-empty DB)...\t\t"
234 output=$(NOTMUCH_NEW)
235 pass_if_equal "$output" "No new mail."
236
237 printf " New directories...\t\t\t\t"
238 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
239 mkdir ${MAIL_DIR}/def
240 mkdir ${MAIL_DIR}/ghi
241 generate_message [dir]=def
242
243 output=$(NOTMUCH_NEW)
244 pass_if_equal "$output" "Added 1 new message to the database."
245
246 printf " Alternate inode order...\t\t\t"
247
248 rm -rf ${MAIL_DIR}/.notmuch
249 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
250 rm ${MAIL_DIR}/def/*
251 generate_message [dir]=abc
252
253 output=$(NOTMUCH_NEW)
254 pass_if_equal "$output" "Added 1 new message to the database."
255
256 printf " Message moved in...\t\t\t\t"
257 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
258 generate_message
259 tmp_msg_filename=tmp/$gen_msg_filename
260 mkdir -p $(dirname $tmp_msg_filename)
261 mv $gen_msg_filename $tmp_msg_filename
262 increment_mtime ${MAIL_DIR}
263 $NOTMUCH new > /dev/null
264 mv $tmp_msg_filename $gen_msg_filename
265 increment_mtime ${MAIL_DIR}
266 output=$(NOTMUCH_NEW)
267 pass_if_equal "$output" "Added 1 new message to the database."
268
269 printf " Renamed message...\t\t\t\t"
270
271 generate_message
272 $NOTMUCH new > /dev/null
273 mv $gen_msg_filename ${gen_msg_filename}-renamed
274 increment_mtime ${MAIL_DIR}
275 output=$(NOTMUCH_NEW)
276 pass_if_equal "$output" "No new mail. Detected 1 file rename."
277
278 printf " Deleted message...\t\t\t\t"
279
280 rm ${gen_msg_filename}-renamed
281 increment_mtime ${MAIL_DIR}
282 output=$(NOTMUCH_NEW)
283 pass_if_equal "$output" "No new mail. Removed 1 message."
284
285 printf " Renamed directory...\t\t\t\t"
286
287 generate_message [dir]=dir
288 generate_message [dir]=dir
289 generate_message [dir]=dir
290
291 $NOTMUCH new > /dev/null
292
293 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
294 increment_mtime ${MAIL_DIR}
295
296 output=$(NOTMUCH_NEW)
297 pass_if_equal "$output" "No new mail. Detected 3 file renames."
298
299 printf " Deleted directory...\t\t\t\t"
300
301 rm -rf ${MAIL_DIR}/dir-renamed
302 increment_mtime ${MAIL_DIR}
303
304 output=$(NOTMUCH_NEW)
305 pass_if_equal "$output" "No new mail. Removed 3 messages."
306
307 printf " New directory (at end of list)...\t\t"
308
309 generate_message [dir]=zzz
310 generate_message [dir]=zzz
311 generate_message [dir]=zzz
312
313 output=$(NOTMUCH_NEW)
314 pass_if_equal "$output" "Added 3 new messages to the database."
315
316 printf " Deleted directory (end of list)...\t\t"
317
318 rm -rf ${MAIL_DIR}/zzz
319 increment_mtime ${MAIL_DIR}
320
321 output=$(NOTMUCH_NEW)
322 pass_if_equal "$output" "No new mail. Removed 3 messages."
323
324 printf " New symlink to directory...\t\t\t"
325
326 rm -rf ${MAIL_DIR}/.notmuch
327 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
328
329 mkdir ${MAIL_DIR}
330 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
331
332 output=$(NOTMUCH_NEW)
333 pass_if_equal "$output" "Added 1 new message to the database."
334
335 printf " New symlink to a file...\t\t\t"
336 generate_message
337 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
338 mkdir -p $(dirname $external_msg_filename)
339 mv $gen_msg_filename $external_msg_filename
340 ln -s $external_msg_filename $gen_msg_filename
341 increment_mtime ${MAIL_DIR}
342 output=$(NOTMUCH_NEW)
343 pass_if_equal "$output" "Added 1 new message to the database."
344
345 printf " New two-level directory...\t\t\t"
346
347 generate_message [dir]=two/levels
348 generate_message [dir]=two/levels
349 generate_message [dir]=two/levels
350
351 output=$(NOTMUCH_NEW)
352 pass_if_equal "$output" "Added 3 new messages to the database."
353
354 printf " Deleted two-level directory...\t\t\t"
355
356 rm -rf ${MAIL_DIR}/two
357 increment_mtime ${MAIL_DIR}
358
359 output=$(NOTMUCH_NEW)
360 pass_if_equal "$output" "No new mail. Removed 3 messages."
361
362 printf "\nTesting \"notmuch search\" in several variations:\n"
363
364 printf " Search body...\t\t\t\t\t"
365 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
366 output=$($NOTMUCH search bodysearchtest | notmuch_search_sanitize)
367 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
368
369 printf " Search by from:...\t\t\t\t"
370 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
371 output=$($NOTMUCH search from:searchbyfrom | notmuch_search_sanitize)
372 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
373
374 printf " Search by to:...\t\t\t\t"
375 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
376 output=$($NOTMUCH search to:searchbyto | notmuch_search_sanitize)
377 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
378
379 printf " Search by subject:...\t\t\t\t"
380 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
381 output=$($NOTMUCH search subject:subjectsearchtest | notmuch_search_sanitize)
382 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
383
384 printf " Search by id:...\t\t\t\t"
385 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
386 output=$($NOTMUCH search id:${gen_msg_id} | notmuch_search_sanitize)
387 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
388
389 printf " Search by tag:...\t\t\t\t"
390 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
391 $NOTMUCH tag +searchbytag id:${gen_msg_id}
392 output=$($NOTMUCH search tag:searchbytag | notmuch_search_sanitize)
393 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
394
395 printf " Search by thread:...\t\t\t\t"
396 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
397 thread_id=$($NOTMUCH search id:${gen_msg_id} | sed -e 's/thread:\([a-f0-9]*\).*/\1/')
398 output=$($NOTMUCH search thread:${thread_id} | notmuch_search_sanitize)
399 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
400
401 printf " Search body (phrase)...\t\t\t"
402 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
403 add_message '[subject]="negative result"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="This phrase should not match the body search"'
404 output=$($NOTMUCH search '\"body search (phrase)\"' | notmuch_search_sanitize)
405 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
406
407 printf " Search by from: (address)...\t\t\t"
408 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
409 output=$($NOTMUCH search from:searchbyfrom@example.com | notmuch_search_sanitize)
410 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
411
412 printf " Search by from: (name)...\t\t\t"
413 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
414 output=$($NOTMUCH search from:'Search By From Name' | notmuch_search_sanitize)
415 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
416
417 printf " Search by to: (address)...\t\t\t"
418 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
419 output=$($NOTMUCH search to:searchbyto@example.com | notmuch_search_sanitize)
420 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
421
422 printf " Search by to: (name)...\t\t\t"
423 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
424 output=$($NOTMUCH search to:'Search By To Name' | notmuch_search_sanitize)
425 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
426
427 printf " Search by subject: (phrase)...\t\t\t"
428 add_message '[subject]="subject search test (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
429 add_message '[subject]="this phrase should not match the subject search test"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
430 output=$($NOTMUCH search 'subject:\"subject search test (phrase)\"' | notmuch_search_sanitize)
431 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)"
432
433 printf " Search for all messages (\"*\"):...\t\t"
434 output=$($NOTMUCH search '*' | notmuch_search_sanitize)
435 pass_if_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #6 (inbox unread)
436 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #14 (inbox unread)
437 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)
438 thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)
439 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
440 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
441 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)
442 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)
443 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)
444 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)
445 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; negative result (inbox unread)
446 thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)
447 thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)
448 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
449 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
450 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)
451 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)"
452
453 printf "\nTesting naming of threads with changing subject:\n"
454 add_message '[subject]="thread-naming: Initial thread subject"' \
455             '[date]="Fri, 05 Jan 2001 15:43:56 -0800"'
456 first=${gen_msg_cnt}
457 parent=${gen_msg_id}
458 add_message '[subject]="thread-naming: Older changed subject"' \
459             '[date]="Sat, 06 Jan 2001 15:43:56 -0800"' \
460             "[in-reply-to]=\<$parent\>"
461 add_message '[subject]="thread-naming: Newer changed subject"' \
462             '[date]="Sun, 07 Jan 2001 15:43:56 -0800"' \
463             "[in-reply-to]=\<$parent\>"
464 add_message '[subject]="thread-naming: Final thread subject"' \
465             '[date]="Mon, 08 Jan 2001 15:43:56 -0800"' \
466             "[in-reply-to]=\<$parent\>"
467 final=${gen_msg_id}
468
469 printf " Initial thread name (oldest-first search)...\t"
470 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
471 pass_if_equal "$output" "thread:XXX   2001-01-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
472
473 printf " Initial thread name (newest-first search)...\t"
474 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
475 pass_if_equal "$output" "thread:XXX   2001-01-08 [4/4] Notmuch Test Suite; thread-naming: Final thread subject (inbox unread)"
476
477 # Remove oldest and newest messages from search results
478 $NOTMUCH tag -inbox id:$parent or id:$final
479
480 printf " Changed thread name (oldest-first search)...\t"
481 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
482 pass_if_equal "$output" "thread:XXX   2001-01-06 [2/4] Notmuch Test Suite; thread-naming: Older changed subject (inbox unread)"
483
484 printf " Changed thread name (newest-first search)...\t"
485 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
486 pass_if_equal "$output" "thread:XXX   2001-01-07 [2/4] Notmuch Test Suite; thread-naming: Newer changed subject (inbox unread)"
487
488 printf " Ignore added reply prefix (Re:)...\t\t"
489 add_message '[subject]="Re: thread-naming: Initial thread subject"' \
490             '[date]="Tue, 09 Jan 2001 15:43:45 -0800"' \
491             "[in-reply-to]=\<$parent\>"
492 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
493 pass_if_equal "$output" "thread:XXX   2001-01-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
494
495 printf " Ignore added reply prefix (Aw:)...\t\t"
496 add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
497             '[date]="Wed, 10 Jan 2001 15:43:45 -0800"' \
498             "[in-reply-to]=\<$parent\>"
499 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
500 pass_if_equal "$output" "thread:XXX   2001-01-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
501
502 printf " Ignore added reply prefix (Vs:)...\t\t"
503 add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
504             '[date]="Thu, 11 Jan 2001 15:43:45 -0800"' \
505             "[in-reply-to]=\<$parent\>"
506 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
507 pass_if_equal "$output" "thread:XXX   2001-01-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
508
509 printf " Ignore added reply prefix (Sv:)...\t\t"
510 add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
511             '[date]="Fri, 12 Jan 2001 15:43:45 -0800"' \
512             "[in-reply-to]=\<$parent\>"
513 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
514 pass_if_equal "$output" "thread:XXX   2001-01-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
515
516 printf " Test order of messages in \"notmuch show\"\t"
517 output=$($NOTMUCH show thread-naming | notmuch_show_sanitize)
518 pass_if_equal "$output" "\fmessage{ id:msg-$(printf "%03d" $first)@notmuch-test-suite depth:0 match:1 filename:/XXX/mail/msg-$(printf "%03d" $first)
519 \fheader{
520 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (unread)
521 Subject: thread-naming: Initial thread subject
522 From: Notmuch Test Suite <test_suite@notmuchmail.org>
523 To: Notmuch Test Suite <test_suite@notmuchmail.org>
524 Date: Fri, 05 Jan 2001 15:43:56 -0800
525 \fheader}
526 \fbody{
527 \fpart{ ID: 1, Content-type: text/plain
528 This is just a test message (#$first)
529 \fpart}
530 \fbody}
531 \fmessage}
532 \fmessage{ id:msg-$(printf "%03d" $((first + 1)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 1)))
533 \fheader{
534 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-06) (inbox unread)
535 Subject: thread-naming: Older changed subject
536 From: Notmuch Test Suite <test_suite@notmuchmail.org>
537 To: Notmuch Test Suite <test_suite@notmuchmail.org>
538 Date: Sat, 06 Jan 2001 15:43:56 -0800
539 \fheader}
540 \fbody{
541 \fpart{ ID: 1, Content-type: text/plain
542 This is just a test message (#$((first + 1)))
543 \fpart}
544 \fbody}
545 \fmessage}
546 \fmessage{ id:msg-$(printf "%03d" $((first + 2)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 2)))
547 \fheader{
548 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-07) (inbox unread)
549 Subject: thread-naming: Newer changed subject
550 From: Notmuch Test Suite <test_suite@notmuchmail.org>
551 To: Notmuch Test Suite <test_suite@notmuchmail.org>
552 Date: Sun, 07 Jan 2001 15:43:56 -0800
553 \fheader}
554 \fbody{
555 \fpart{ ID: 1, Content-type: text/plain
556 This is just a test message (#$((first + 2)))
557 \fpart}
558 \fbody}
559 \fmessage}
560 \fmessage{ id:msg-$(printf "%03d" $((first + 3)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 3)))
561 \fheader{
562 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-08) (unread)
563 Subject: thread-naming: Final thread subject
564 From: Notmuch Test Suite <test_suite@notmuchmail.org>
565 To: Notmuch Test Suite <test_suite@notmuchmail.org>
566 Date: Mon, 08 Jan 2001 15:43:56 -0800
567 \fheader}
568 \fbody{
569 \fpart{ ID: 1, Content-type: text/plain
570 This is just a test message (#$((first + 3)))
571 \fpart}
572 \fbody}
573 \fmessage}
574 \fmessage{ id:msg-$(printf "%03d" $((first + 4)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 4)))
575 \fheader{
576 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-09) (inbox unread)
577 Subject: Re: thread-naming: Initial thread subject
578 From: Notmuch Test Suite <test_suite@notmuchmail.org>
579 To: Notmuch Test Suite <test_suite@notmuchmail.org>
580 Date: Tue, 09 Jan 2001 15:43:45 -0800
581 \fheader}
582 \fbody{
583 \fpart{ ID: 1, Content-type: text/plain
584 This is just a test message (#$((first + 4)))
585 \fpart}
586 \fbody}
587 \fmessage}
588 \fmessage{ id:msg-$(printf "%03d" $((first + 5)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 5)))
589 \fheader{
590 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-10) (inbox unread)
591 Subject: Aw: thread-naming: Initial thread subject
592 From: Notmuch Test Suite <test_suite@notmuchmail.org>
593 To: Notmuch Test Suite <test_suite@notmuchmail.org>
594 Date: Wed, 10 Jan 2001 15:43:45 -0800
595 \fheader}
596 \fbody{
597 \fpart{ ID: 1, Content-type: text/plain
598 This is just a test message (#$((first + 5)))
599 \fpart}
600 \fbody}
601 \fmessage}
602 \fmessage{ id:msg-$(printf "%03d" $((first + 6)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 6)))
603 \fheader{
604 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-11) (inbox unread)
605 Subject: Vs: thread-naming: Initial thread subject
606 From: Notmuch Test Suite <test_suite@notmuchmail.org>
607 To: Notmuch Test Suite <test_suite@notmuchmail.org>
608 Date: Thu, 11 Jan 2001 15:43:45 -0800
609 \fheader}
610 \fbody{
611 \fpart{ ID: 1, Content-type: text/plain
612 This is just a test message (#$((first + 6)))
613 \fpart}
614 \fbody}
615 \fmessage}
616 \fmessage{ id:msg-$(printf "%03d" $((first + 7)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 7)))
617 \fheader{
618 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-12) (inbox unread)
619 Subject: Sv: thread-naming: Initial thread subject
620 From: Notmuch Test Suite <test_suite@notmuchmail.org>
621 To: Notmuch Test Suite <test_suite@notmuchmail.org>
622 Date: Fri, 12 Jan 2001 15:43:45 -0800
623 \fheader}
624 \fbody{
625 \fpart{ ID: 1, Content-type: text/plain
626 This is just a test message (#$((first + 7)))
627 \fpart}
628 \fbody}
629 \fmessage}"
630
631 printf "\nTesting \"notmuch reply\" in several variations:\n"
632
633 printf " Basic reply...\t\t\t\t\t"
634 add_message '[from]="Sender <sender@example.com>"' \
635              [to]=test_suite@notmuchmail.org \
636              [subject]=notmuch-reply-test \
637             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
638             '[body]="basic reply test"'
639
640 output=$($NOTMUCH reply id:${gen_msg_id})
641 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
642 Subject: Re: notmuch-reply-test
643 To: Sender <sender@example.com>
644 Bcc: test_suite@notmuchmail.org
645 In-Reply-To: <${gen_msg_id}>
646 References: <${gen_msg_id}>
647
648 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
649 > basic reply test"
650
651 printf " Multiple recipients...\t\t\t\t"
652 add_message '[from]="Sender <sender@example.com>"' \
653             '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
654              [subject]=notmuch-reply-test \
655             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
656             '[body]="Multiple recipients"'
657
658 output=$($NOTMUCH reply id:${gen_msg_id})
659 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
660 Subject: Re: notmuch-reply-test
661 To: Sender <sender@example.com>, Someone Else <someone@example.com>
662 Bcc: test_suite@notmuchmail.org
663 In-Reply-To: <${gen_msg_id}>
664 References: <${gen_msg_id}>
665
666 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
667 > Multiple recipients"
668
669 printf " Reply with CC...\t\t\t\t"
670 add_message '[from]="Sender <sender@example.com>"' \
671              [to]=test_suite@notmuchmail.org \
672             '[cc]="Other Parties <cc@example.com>"' \
673              [subject]=notmuch-reply-test \
674             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
675             '[body]="reply with CC"'
676
677 output=$($NOTMUCH reply id:${gen_msg_id})
678 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
679 Subject: Re: notmuch-reply-test
680 To: Sender <sender@example.com>
681 Cc: Other Parties <cc@example.com>
682 Bcc: test_suite@notmuchmail.org
683 In-Reply-To: <${gen_msg_id}>
684 References: <${gen_msg_id}>
685
686 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
687 > reply with CC"
688
689 printf " Reply from alternate address...\t\t"
690 add_message '[from]="Sender <sender@example.com>"' \
691              [to]=test_suite_other@notmuchmail.org \
692              [subject]=notmuch-reply-test \
693             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
694             '[body]="reply from alternate address"'
695
696 output=$($NOTMUCH reply id:${gen_msg_id})
697 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
698 Subject: Re: notmuch-reply-test
699 To: Sender <sender@example.com>
700 Bcc: test_suite@notmuchmail.org
701 In-Reply-To: <${gen_msg_id}>
702 References: <${gen_msg_id}>
703
704 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
705 > reply from alternate address"
706
707 printf " Support for Reply-To...\t\t\t"
708 add_message '[from]="Sender <sender@example.com>"' \
709              [to]=test_suite@notmuchmail.org \
710              [subject]=notmuch-reply-test \
711             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
712             '[body]="support for reply-to"' \
713             '[reply-to]="Sender <elsewhere@example.com>"'
714
715 output=$($NOTMUCH reply id:${gen_msg_id})
716 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
717 Subject: Re: notmuch-reply-test
718 To: Sender <elsewhere@example.com>
719 Bcc: test_suite@notmuchmail.org
720 In-Reply-To: <${gen_msg_id}>
721 References: <${gen_msg_id}>
722
723 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
724 > support for reply-to"
725
726 printf " Un-munging Reply-To...\t\t\t\t"
727 add_message '[from]="Sender <sender@example.com>"' \
728             '[to]="Some List <list@example.com>"' \
729              [subject]=notmuch-reply-test \
730             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
731             '[body]="Un-munging Reply-To"' \
732             '[reply-to]="Evil Munging List <list@example.com>"'
733
734 output=$($NOTMUCH reply id:${gen_msg_id})
735 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
736 Subject: Re: notmuch-reply-test
737 To: Sender <sender@example.com>, Some List <list@example.com>
738 Bcc: test_suite@notmuchmail.org
739 In-Reply-To: <${gen_msg_id}>
740 References: <${gen_msg_id}>
741
742 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
743 > Un-munging Reply-To"
744
745 printf "\nTesting handling of uuencoded data:\n"
746
747 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
748 '[body]="This message is used to ensure that notmuch correctly handles a
749 message containing a block of uuencoded data. First, we have a marker
750 this content beforeuudata . Then we beging the uunencoded data itself:
751
752 begin 644 bogus-uuencoded-data
753 M0123456789012345678901234567890123456789012345678901234567890
754 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.    
755 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA 
756 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE   
757 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY  
758 MSEARCH RESULT.                                               
759 \`
760 end
761
762 Finally, we have our afteruudata marker as well."'
763
764 printf " Ensure content before uu data is indexed...\t"
765 output=$($NOTMUCH search beforeuudata | notmuch_search_sanitize)
766 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
767 printf " Ensure uu data is not indexed...\t\t"
768 output=$($NOTMUCH search DURINGUUDATA | notmuch_search_sanitize)
769 pass_if_equal "$output" ""
770 printf " Ensure content after uu data is indexed...\t"
771 output=$($NOTMUCH search afteruudata | notmuch_search_sanitize)
772 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
773
774 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
775
776 printf " Dumping all tags...\t\t\t\t"
777 $NOTMUCH dump dump.expected
778 pass_if_equal "$?" "0"
779
780 printf " Clearing all tags...\t\t\t\t"
781 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
782 $NOTMUCH restore clear.expected
783 $NOTMUCH dump clear.actual
784 pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
785
786 printf " Restoring original tags...\t\t\t"
787 $NOTMUCH restore dump.expected
788 $NOTMUCH dump dump.actual
789 pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
790
791 printf " Restore with nothing to do...\t\t\t"
792 $NOTMUCH restore dump.expected
793 pass_if_equal "$?" "0"
794
795 printf "\nTesting threading when messages received out of order:\n"
796 printf " Adding initial child message...\t\t"
797 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
798 output=$(NOTMUCH_NEW)
799 pass_if_equal "$output" "Added 1 new message to the database."
800 printf " Searching returns the message...\t\t"
801 output=$($NOTMUCH search foo | notmuch_search_sanitize)
802 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
803 printf " Adding second child message...\t\t\t"
804 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
805 output=$(NOTMUCH_NEW)
806 pass_if_equal "$output" "Added 1 new message to the database."
807 printf " Searching returns both messages in one thread..."
808 output=$($NOTMUCH search foo | notmuch_search_sanitize)
809 pass_if_equal "$output" "thread:XXX   2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
810 printf " Adding parent message...\t\t\t"
811 generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
812 output=$(NOTMUCH_NEW)
813 pass_if_equal "$output" "Added 1 new message to the database."
814 printf " Searching returns all three messages in one thread..."
815 output=$($NOTMUCH search foo | notmuch_search_sanitize)
816 pass_if_equal "$output" "thread:XXX   2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
817
818 echo ""
819 echo "Notmuch test suite complete."
820
821 if [ "$test_failures" = "0" ]; then
822     echo "All $tests tests passed."
823     rm -rf ${TEST_DIR}
824 else
825     echo "$test_failures/$tests tests failed. The failures can be investigated in:"
826     echo "${TEST_DIR}"
827 fi
828
829 echo ""
830
831 exit $test_failures