]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test
test: When a test fails, show diff only (save complete output to a file)
[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 rm -rf ${TEST_DIR}
196 mkdir ${TEST_DIR}
197 cd ${TEST_DIR}
198
199 mkdir ${MAIL_DIR}
200
201 cat <<EOF > ${NOTMUCH_CONFIG}
202 [database]
203 path=${MAIL_DIR}
204
205 [user]
206 name=Notmuch Test Suite
207 primary_email=test_suite@notmuchmail.org
208 other_email=test_suite_other@notmuchmail.org
209 EOF
210
211 printf "Testing \"notmuch new\" in several variations:\n"
212 printf " No new messages...\t\t\t\t"
213 output=$(NOTMUCH_NEW)
214 pass_if_equal "$output" "No new mail."
215
216 printf " Single new message...\t\t\t\t"
217 generate_message
218 output=$(NOTMUCH_NEW)
219 pass_if_equal "$output" "Added 1 new message to the database."
220
221 printf " Multiple new messages...\t\t\t"
222 generate_message
223 generate_message
224 output=$(NOTMUCH_NEW)
225 pass_if_equal "$output" "Added 2 new messages to the database."
226
227 printf " No new messages (non-empty DB)...\t\t"
228 output=$(NOTMUCH_NEW)
229 pass_if_equal "$output" "No new mail."
230
231 printf " New directories...\t\t\t\t"
232 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
233 mkdir ${MAIL_DIR}/def
234 mkdir ${MAIL_DIR}/ghi
235 generate_message [dir]=def
236
237 output=$(NOTMUCH_NEW)
238 pass_if_equal "$output" "Added 1 new message to the database."
239
240 printf " Alternate inode order...\t\t\t"
241
242 rm -rf ${MAIL_DIR}/.notmuch
243 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
244 rm ${MAIL_DIR}/def/*
245 generate_message [dir]=abc
246
247 output=$(NOTMUCH_NEW)
248 pass_if_equal "$output" "Added 1 new message to the database."
249
250 printf " Message moved in...\t\t\t\t"
251 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
252 generate_message
253 tmp_msg_filename=tmp/$gen_msg_filename
254 mkdir -p $(dirname $tmp_msg_filename)
255 mv $gen_msg_filename $tmp_msg_filename
256 increment_mtime ${MAIL_DIR}
257 $NOTMUCH new > /dev/null
258 mv $tmp_msg_filename $gen_msg_filename
259 increment_mtime ${MAIL_DIR}
260 output=$(NOTMUCH_NEW)
261 pass_if_equal "$output" "Added 1 new message to the database."
262
263 printf " Renamed message...\t\t\t\t"
264
265 generate_message
266 $NOTMUCH new > /dev/null
267 mv $gen_msg_filename ${gen_msg_filename}-renamed
268 increment_mtime ${MAIL_DIR}
269 output=$(NOTMUCH_NEW)
270 pass_if_equal "$output" "No new mail. Detected 1 file rename."
271
272 printf " Deleted message...\t\t\t\t"
273
274 rm ${gen_msg_filename}-renamed
275 increment_mtime ${MAIL_DIR}
276 output=$(NOTMUCH_NEW)
277 pass_if_equal "$output" "No new mail. Removed 1 message."
278
279 printf " Renamed directory...\t\t\t\t"
280
281 generate_message [dir]=dir
282 generate_message [dir]=dir
283 generate_message [dir]=dir
284
285 $NOTMUCH new > /dev/null
286
287 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
288 increment_mtime ${MAIL_DIR}
289
290 output=$(NOTMUCH_NEW)
291 pass_if_equal "$output" "No new mail. Detected 3 file renames."
292
293 printf " Deleted directory...\t\t\t\t"
294
295 rm -rf ${MAIL_DIR}/dir-renamed
296 increment_mtime ${MAIL_DIR}
297
298 output=$(NOTMUCH_NEW)
299 pass_if_equal "$output" "No new mail. Removed 3 messages."
300
301 printf " New directory (at end of list)...\t\t"
302
303 generate_message [dir]=zzz
304 generate_message [dir]=zzz
305 generate_message [dir]=zzz
306
307 output=$(NOTMUCH_NEW)
308 pass_if_equal "$output" "Added 3 new messages to the database."
309
310 printf " Deleted directory (end of list)...\t\t"
311
312 rm -rf ${MAIL_DIR}/zzz
313 increment_mtime ${MAIL_DIR}
314
315 output=$(NOTMUCH_NEW)
316 pass_if_equal "$output" "No new mail. Removed 3 messages."
317
318 printf " New symlink to directory...\t\t\t"
319
320 rm -rf ${MAIL_DIR}/.notmuch
321 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
322
323 mkdir ${MAIL_DIR}
324 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
325
326 output=$(NOTMUCH_NEW)
327 pass_if_equal "$output" "Added 1 new message to the database."
328
329 printf " New symlink to a file...\t\t\t"
330 generate_message
331 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
332 mkdir -p $(dirname $external_msg_filename)
333 mv $gen_msg_filename $external_msg_filename
334 ln -s $external_msg_filename $gen_msg_filename
335 increment_mtime ${MAIL_DIR}
336 output=$(NOTMUCH_NEW)
337 pass_if_equal "$output" "Added 1 new message to the database."
338
339 printf " New two-level directory...\t\t\t"
340
341 generate_message [dir]=two/levels
342 generate_message [dir]=two/levels
343 generate_message [dir]=two/levels
344
345 output=$(NOTMUCH_NEW)
346 pass_if_equal "$output" "Added 3 new messages to the database."
347
348 printf " Deleted two-level directory...\t\t\t"
349
350 rm -rf ${MAIL_DIR}/two
351 increment_mtime ${MAIL_DIR}
352
353 output=$(NOTMUCH_NEW)
354 pass_if_equal "$output" "No new mail. Removed 3 messages."
355
356 printf "\nTesting \"notmuch search\" in several variations:\n"
357
358 printf " Search body...\t\t\t\t\t"
359 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
360 output=$($NOTMUCH search bodysearchtest | notmuch_search_sanitize)
361 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
362
363 printf " Search by from:...\t\t\t\t"
364 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
365 output=$($NOTMUCH search from:searchbyfrom | notmuch_search_sanitize)
366 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
367
368 printf " Search by to:...\t\t\t\t"
369 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
370 output=$($NOTMUCH search to:searchbyto | notmuch_search_sanitize)
371 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
372
373 printf " Search by subject:...\t\t\t\t"
374 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
375 output=$($NOTMUCH search subject:subjectsearchtest | notmuch_search_sanitize)
376 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
377
378 printf " Search by id:...\t\t\t\t"
379 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
380 output=$($NOTMUCH search id:${gen_msg_id} | notmuch_search_sanitize)
381 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
382
383 printf " Search by tag:...\t\t\t\t"
384 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
385 $NOTMUCH tag +searchbytag id:${gen_msg_id}
386 output=$($NOTMUCH search tag:searchbytag | notmuch_search_sanitize)
387 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
388
389 printf " Search by thread:...\t\t\t\t"
390 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
391 thread_id=$($NOTMUCH search id:${gen_msg_id} | sed -e 's/thread:\([a-f0-9]*\).*/\1/')
392 output=$($NOTMUCH search thread:${thread_id} | notmuch_search_sanitize)
393 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
394
395 printf " Search body (phrase)...\t\t\t"
396 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
397 add_message '[subject]="negative result"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="This phrase should not match the body search"'
398 output=$($NOTMUCH search '\"body search (phrase)\"' | notmuch_search_sanitize)
399 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
400
401 printf " Search by from: (address)...\t\t\t"
402 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
403 output=$($NOTMUCH search from:searchbyfrom@example.com | notmuch_search_sanitize)
404 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
405
406 printf " Search by from: (name)...\t\t\t"
407 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
408 output=$($NOTMUCH search from:'Search By From Name' | notmuch_search_sanitize)
409 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
410
411 printf " Search by to: (address)...\t\t\t"
412 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
413 output=$($NOTMUCH search to:searchbyto@example.com | notmuch_search_sanitize)
414 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
415
416 printf " Search by to: (name)...\t\t\t"
417 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
418 output=$($NOTMUCH search to:'Search By To Name' | notmuch_search_sanitize)
419 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
420
421 printf " Search by subject: (phrase)...\t\t\t"
422 add_message '[subject]="subject search test (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
423 add_message '[subject]="this phrase should not match the subject search test"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
424 output=$($NOTMUCH search 'subject:\"subject search test (phrase)\"' | notmuch_search_sanitize)
425 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)"
426
427 printf " Search for all messages (\"*\"):...\t\t"
428 output=$($NOTMUCH search '*' | notmuch_search_sanitize)
429 pass_if_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #6 (inbox unread)
430 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #14 (inbox unread)
431 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)
432 thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)
433 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
434 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
435 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)
436 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)
437 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)
438 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)
439 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; negative result (inbox unread)
440 thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)
441 thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)
442 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
443 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
444 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)
445 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)"
446
447 printf "\nTesting naming of threads with changing subject:\n"
448 add_message '[subject]="thread-naming: Initial thread subject"' \
449             '[date]="Fri, 05 Jan 2001 15:43:56 -0800"'
450 parent=${gen_msg_id}
451 add_message '[subject]="thread-naming: Older changed subject"' \
452             '[date]="Sat, 06 Jan 2001 15:43:56 -0800"' \
453             "[in-reply-to]=\<$parent\>"
454 add_message '[subject]="thread-naming: Newer changed subject"' \
455             '[date]="Sun, 07 Jan 2001 15:43:56 -0800"' \
456             "[in-reply-to]=\<$parent\>"
457 add_message '[subject]="thread-naming: Final thread subject"' \
458             '[date]="Mon, 08 Jan 2001 15:43:56 -0800"' \
459             "[in-reply-to]=\<$parent\>"
460 final=${gen_msg_id}
461
462 printf " Initial thread name (oldest-first search)...\t"
463 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
464 pass_if_equal "$output" "thread:XXX   2001-01-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
465
466 printf " Initial thread name (newest-first search)...\t"
467 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
468 pass_if_equal "$output" "thread:XXX   2001-01-08 [4/4] Notmuch Test Suite; thread-naming: Final thread subject (inbox unread)"
469
470 # Remove oldest and newest messages from search results
471 $NOTMUCH tag -inbox id:$parent or id:$final
472
473 printf " Changed thread name (oldest-first search)...\t"
474 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
475 pass_if_equal "$output" "thread:XXX   2001-01-06 [2/4] Notmuch Test Suite; thread-naming: Older changed subject (inbox unread)"
476
477 printf " Changed thread name (newest-first search)...\t"
478 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
479 pass_if_equal "$output" "thread:XXX   2001-01-07 [2/4] Notmuch Test Suite; thread-naming: Newer changed subject (inbox unread)"
480
481 printf " Ignore added reply prefix (Re:)...\t\t"
482 add_message '[subject]="Re: thread-naming: Initial thread subject"' \
483             '[date]="Tue, 09 Jan 2001 15:43:45 -0800"' \
484             "[in-reply-to]=\<$parent\>"
485 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
486 pass_if_equal "$output" "thread:XXX   2001-01-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
487
488 printf " Ignore added reply prefix (Aw:)...\t\t"
489 add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
490             '[date]="Wed, 10 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-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
494
495 printf " Ignore added reply prefix (Vs:)...\t\t"
496 add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
497             '[date]="Thu, 11 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-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
501
502 printf " Ignore added reply prefix (Sv:)...\t\t"
503 add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
504             '[date]="Fri, 12 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-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
508
509 printf "\nTesting \"notmuch reply\" in several variations:\n"
510
511 printf " Basic reply...\t\t\t\t\t"
512 add_message '[from]="Sender <sender@example.com>"' \
513              [to]=test_suite@notmuchmail.org \
514              [subject]=notmuch-reply-test \
515             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
516             '[body]="basic reply test"'
517
518 output=$($NOTMUCH reply id:${gen_msg_id})
519 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
520 Subject: Re: notmuch-reply-test
521 To: Sender <sender@example.com>
522 Bcc: test_suite@notmuchmail.org
523 In-Reply-To: <${gen_msg_id}>
524 References: <${gen_msg_id}>
525
526 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
527 > basic reply test"
528
529 printf " Multiple recipients...\t\t\t\t"
530 add_message '[from]="Sender <sender@example.com>"' \
531             '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
532              [subject]=notmuch-reply-test \
533             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
534             '[body]="Multiple recipients"'
535
536 output=$($NOTMUCH reply id:${gen_msg_id})
537 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
538 Subject: Re: notmuch-reply-test
539 To: Sender <sender@example.com>, Someone Else <someone@example.com>
540 Bcc: test_suite@notmuchmail.org
541 In-Reply-To: <${gen_msg_id}>
542 References: <${gen_msg_id}>
543
544 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
545 > Multiple recipients"
546
547 printf " Reply with CC...\t\t\t\t"
548 add_message '[from]="Sender <sender@example.com>"' \
549              [to]=test_suite@notmuchmail.org \
550             '[cc]="Other Parties <cc@example.com>"' \
551              [subject]=notmuch-reply-test \
552             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
553             '[body]="reply with CC"'
554
555 output=$($NOTMUCH reply id:${gen_msg_id})
556 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
557 Subject: Re: notmuch-reply-test
558 To: Sender <sender@example.com>
559 Cc: Other Parties <cc@example.com>
560 Bcc: test_suite@notmuchmail.org
561 In-Reply-To: <${gen_msg_id}>
562 References: <${gen_msg_id}>
563
564 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
565 > reply with CC"
566
567 printf " Reply from alternate address...\t\t"
568 add_message '[from]="Sender <sender@example.com>"' \
569              [to]=test_suite_other@notmuchmail.org \
570              [subject]=notmuch-reply-test \
571             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
572             '[body]="reply from alternate address"'
573
574 output=$($NOTMUCH reply id:${gen_msg_id})
575 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
576 Subject: Re: notmuch-reply-test
577 To: Sender <sender@example.com>
578 Bcc: test_suite@notmuchmail.org
579 In-Reply-To: <${gen_msg_id}>
580 References: <${gen_msg_id}>
581
582 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
583 > reply from alternate address"
584
585 printf " Support for Reply-To...\t\t\t"
586 add_message '[from]="Sender <sender@example.com>"' \
587              [to]=test_suite@notmuchmail.org \
588              [subject]=notmuch-reply-test \
589             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
590             '[body]="support for reply-to"' \
591             '[reply-to]="Sender <elsewhere@example.com>"'
592
593 output=$($NOTMUCH reply id:${gen_msg_id})
594 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
595 Subject: Re: notmuch-reply-test
596 To: Sender <elsewhere@example.com>
597 Bcc: test_suite@notmuchmail.org
598 In-Reply-To: <${gen_msg_id}>
599 References: <${gen_msg_id}>
600
601 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
602 > support for reply-to"
603
604 printf " Un-munging Reply-To...\t\t\t\t"
605 add_message '[from]="Sender <sender@example.com>"' \
606             '[to]="Some List <list@example.com>"' \
607              [subject]=notmuch-reply-test \
608             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
609             '[body]="Un-munging Reply-To"' \
610             '[reply-to]="Evil Munging List <list@example.com>"'
611
612 output=$($NOTMUCH reply id:${gen_msg_id})
613 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
614 Subject: Re: notmuch-reply-test
615 To: Sender <sender@example.com>, Some List <list@example.com>
616 Bcc: test_suite@notmuchmail.org
617 In-Reply-To: <${gen_msg_id}>
618 References: <${gen_msg_id}>
619
620 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
621 > Un-munging Reply-To"
622
623 printf "\nTesting handling of uuencoded data:\n"
624
625 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
626 '[body]="This message is used to ensure that notmuch correctly handles a
627 message containing a block of uuencoded data. First, we have a marker
628 this content beforeuudata . Then we beging the uunencoded data itself:
629
630 begin 644 bogus-uuencoded-data
631 M0123456789012345678901234567890123456789012345678901234567890
632 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.    
633 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA 
634 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE   
635 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY  
636 MSEARCH RESULT.                                               
637 \`
638 end
639
640 Finally, we have our afteruudata marker as well."'
641
642 printf " Ensure content before uu data is indexed...\t"
643 output=$($NOTMUCH search beforeuudata | notmuch_search_sanitize)
644 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
645 printf " Ensure uu data is not indexed...\t\t"
646 output=$($NOTMUCH search DURINGUUDATA | notmuch_search_sanitize)
647 pass_if_equal "$output" ""
648 printf " Ensure content after uu data is indexed...\t"
649 output=$($NOTMUCH search afteruudata | notmuch_search_sanitize)
650 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
651
652 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
653
654 printf " Dumping all tags...\t\t\t\t"
655 $NOTMUCH dump dump.expected
656 pass_if_equal "$?" "0"
657
658 printf " Clearing all tags...\t\t\t\t"
659 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
660 $NOTMUCH restore clear.expected
661 $NOTMUCH dump clear.actual
662 pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
663
664 printf " Restoring original tags...\t\t\t"
665 $NOTMUCH restore dump.expected
666 $NOTMUCH dump dump.actual
667 pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
668
669 printf " Restore with nothing to do...\t\t\t"
670 $NOTMUCH restore dump.expected
671 pass_if_equal "$?" "0"
672
673 printf "\nTesting threading when messages received out of order:\n"
674 printf " Adding initial child message...\t\t"
675 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
676 output=$(NOTMUCH_NEW)
677 pass_if_equal "$output" "Added 1 new message to the database."
678 printf " Searching returns the message...\t\t"
679 output=$($NOTMUCH search foo | notmuch_search_sanitize)
680 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
681 printf " Adding second child message...\t\t\t"
682 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
683 output=$(NOTMUCH_NEW)
684 pass_if_equal "$output" "Added 1 new message to the database."
685 printf " Searching returns both messages in one thread..."
686 output=$($NOTMUCH search foo | notmuch_search_sanitize)
687 pass_if_equal "$output" "thread:XXX   2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
688 printf " Adding parent message...\t\t\t"
689 generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
690 output=$(NOTMUCH_NEW)
691 pass_if_equal "$output" "Added 1 new message to the database."
692 printf " Searching returns all three messages in one thread..."
693 output=$($NOTMUCH search foo | notmuch_search_sanitize)
694 pass_if_equal "$output" "thread:XXX   2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
695
696 echo ""
697 echo "Notmuch test suite complete."
698
699 if [ "$test_failures" = "0" ]; then
700     echo "All $tests tests passed."
701     rm -rf ${TEST_DIR}
702 else
703     echo "$test_failures/$tests tests failed. The failures can be investigated in:"
704     echo "${TEST_DIR}"
705 fi
706
707 echo ""
708
709 exit $test_failures