]> git.notmuchmail.org Git - notmuch/blobdiff - test/notmuch-test
Add 'G' keybinding to folder and search view that triggers external poll
[notmuch] / test / notmuch-test
index ba1e70f6fb7c48d6c6bd1fbee27366069b686c4f..1956001254dad125cafdfd6b7460a11d1eaf71e8 100755 (executable)
@@ -94,7 +94,7 @@ generate_message ()
     fi
 
     if [ -z "${template[body]}" ]; then
-       template[body]="This is just test message (#${gen_msg_cnt})"
+       template[body]="This is just test message (#${gen_msg_cnt})"
     fi
 
     if [ -z "${template[from]}" ]; then
@@ -146,7 +146,7 @@ EOF
 # Generate a new message and add it to the index.
 #
 # All of the arguments and return values supported by generate_message
-# are alos supported here, so see that function for details.
+# are also supported here, so see that function for details.
 add_message ()
 {
     generate_message "$@"
@@ -154,17 +154,25 @@ add_message ()
     $NOTMUCH new > /dev/null
 }
 
+tests=0
+test_failures=0
+
 pass_if_equal ()
 {
     output=$1
     expected=$2
 
+    tests=$((tests + 1))
+
     if [ "$output" = "$expected" ]; then
        echo "  PASS"
     else
        echo "  FAIL"
-       echo "  Expected output: $expected"
-       echo "  Actual output:   $output"
+       testname=test-$(printf "%03d" $tests)
+       echo "$expected" > $testname.expected
+       echo "$output" > $testname.output
+       diff -u $testname.expected $testname.output || true
+       test_failures=$((test_failures + 1))
     fi
 }
 
@@ -184,6 +192,12 @@ notmuch_search_sanitize ()
     sed -e "$NOTMUCH_SEARCH_THREAD_ID_SQUELCH"
 }
 
+NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
+notmuch_show_sanitize ()
+{
+    sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
+}
+
 rm -rf ${TEST_DIR}
 mkdir ${TEST_DIR}
 cd ${TEST_DIR}
@@ -436,6 +450,183 @@ thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unr
 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)
 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)"
 
+printf "\nTesting naming of threads with changing subject:\n"
+add_message '[subject]="thread-naming: Initial thread subject"' \
+            '[date]="Fri, 05 Jan 2001 15:43:56 -0800"'
+parent=${gen_msg_id}
+add_message '[subject]="thread-naming: Older changed subject"' \
+            '[date]="Sat, 06 Jan 2001 15:43:56 -0800"' \
+            "[in-reply-to]=\<$parent\>"
+add_message '[subject]="thread-naming: Newer changed subject"' \
+            '[date]="Sun, 07 Jan 2001 15:43:56 -0800"' \
+            "[in-reply-to]=\<$parent\>"
+add_message '[subject]="thread-naming: Final thread subject"' \
+            '[date]="Mon, 08 Jan 2001 15:43:56 -0800"' \
+            "[in-reply-to]=\<$parent\>"
+final=${gen_msg_id}
+
+printf " Initial thread name (oldest-first search)...\t"
+output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX   2001-01-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
+
+printf " Initial thread name (newest-first search)...\t"
+output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX   2001-01-08 [4/4] Notmuch Test Suite; thread-naming: Final thread subject (inbox unread)"
+
+# Remove oldest and newest messages from search results
+$NOTMUCH tag -inbox id:$parent or id:$final
+
+printf " Changed thread name (oldest-first search)...\t"
+output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX   2001-01-06 [2/4] Notmuch Test Suite; thread-naming: Older changed subject (inbox unread)"
+
+printf " Changed thread name (newest-first search)...\t"
+output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX   2001-01-07 [2/4] Notmuch Test Suite; thread-naming: Newer changed subject (inbox unread)"
+
+printf " Ignore added reply prefix (Re:)...\t\t"
+add_message '[subject]="Re: thread-naming: Initial thread subject"' \
+            '[date]="Tue, 09 Jan 2001 15:43:45 -0800"' \
+            "[in-reply-to]=\<$parent\>"
+output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX   2001-01-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
+
+printf " Ignore added reply prefix (Aw:)...\t\t"
+add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
+            '[date]="Wed, 10 Jan 2001 15:43:45 -0800"' \
+            "[in-reply-to]=\<$parent\>"
+output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX   2001-01-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
+
+printf " Ignore added reply prefix (Vs:)...\t\t"
+add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
+            '[date]="Thu, 11 Jan 2001 15:43:45 -0800"' \
+            "[in-reply-to]=\<$parent\>"
+output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX   2001-01-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
+
+printf " Ignore added reply prefix (Sv:)...\t\t"
+add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
+            '[date]="Fri, 12 Jan 2001 15:43:45 -0800"' \
+            "[in-reply-to]=\<$parent\>"
+output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX   2001-01-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
+
+printf " Test order of messages in \"notmuch show\"\t"
+output=$($NOTMUCH show thread-naming | notmuch_show_sanitize)
+pass_if_equal "$output" "\fmessage{ id:msg-033@notmuch-test-suite depth:0 match:1 filename:/XXX/mail/msg-033
+\fheader{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (unread)
+Subject: thread-naming: Initial thread subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Fri, 05 Jan 2001 15:43:56 -0800
+\fheader}
+\fbody{
+\fpart{ ID: 1, Content-type: text/plain
+This is just a test message (#33)
+\fpart}
+\fbody}
+\fmessage}
+\fmessage{ id:msg-034@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-034
+\fheader{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-06) (inbox unread)
+Subject: thread-naming: Older changed subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Sat, 06 Jan 2001 15:43:56 -0800
+\fheader}
+\fbody{
+\fpart{ ID: 1, Content-type: text/plain
+This is just a test message (#34)
+\fpart}
+\fbody}
+\fmessage}
+\fmessage{ id:msg-035@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-035
+\fheader{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-07) (inbox unread)
+Subject: thread-naming: Newer changed subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Sun, 07 Jan 2001 15:43:56 -0800
+\fheader}
+\fbody{
+\fpart{ ID: 1, Content-type: text/plain
+This is just a test message (#35)
+\fpart}
+\fbody}
+\fmessage}
+\fmessage{ id:msg-036@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-036
+\fheader{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-08) (unread)
+Subject: thread-naming: Final thread subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Mon, 08 Jan 2001 15:43:56 -0800
+\fheader}
+\fbody{
+\fpart{ ID: 1, Content-type: text/plain
+This is just a test message (#36)
+\fpart}
+\fbody}
+\fmessage}
+\fmessage{ id:msg-037@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-037
+\fheader{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-09) (inbox unread)
+Subject: Re: thread-naming: Initial thread subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Tue, 09 Jan 2001 15:43:45 -0800
+\fheader}
+\fbody{
+\fpart{ ID: 1, Content-type: text/plain
+This is just a test message (#37)
+\fpart}
+\fbody}
+\fmessage}
+\fmessage{ id:msg-038@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-038
+\fheader{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-10) (inbox unread)
+Subject: Aw: thread-naming: Initial thread subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Wed, 10 Jan 2001 15:43:45 -0800
+\fheader}
+\fbody{
+\fpart{ ID: 1, Content-type: text/plain
+This is just a test message (#38)
+\fpart}
+\fbody}
+\fmessage}
+\fmessage{ id:msg-039@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-039
+\fheader{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-11) (inbox unread)
+Subject: Vs: thread-naming: Initial thread subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Thu, 11 Jan 2001 15:43:45 -0800
+\fheader}
+\fbody{
+\fpart{ ID: 1, Content-type: text/plain
+This is just a test message (#39)
+\fpart}
+\fbody}
+\fmessage}
+\fmessage{ id:msg-040@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-040
+\fheader{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-12) (inbox unread)
+Subject: Sv: thread-naming: Initial thread subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Fri, 12 Jan 2001 15:43:45 -0800
+\fheader}
+\fbody{
+\fpart{ ID: 1, Content-type: text/plain
+This is just a test message (#40)
+\fpart}
+\fbody}
+\fmessage}"
+
 printf "\nTesting \"notmuch reply\" in several variations:\n"
 
 printf " Basic reply...\t\t\t\t\t"
@@ -583,34 +774,22 @@ printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
 
 printf " Dumping all tags...\t\t\t\t"
 $NOTMUCH dump dump.expected
-echo " PASS"
+pass_if_equal "$?" "0"
 
 printf " Clearing all tags...\t\t\t\t"
 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
 $NOTMUCH restore clear.expected
 $NOTMUCH dump clear.actual
-if diff clear.expected clear.actual > /dev/null; then
-    echo "     PASS"
-else
-    echo "     FAIL"
-    echo "     Expected output: See file clear.expected"
-    echo "     Actual output:   See file clear.actual"
-fi
+pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
 
 printf " Restoring original tags...\t\t\t"
 $NOTMUCH restore dump.expected
 $NOTMUCH dump dump.actual
-if diff dump.expected dump.actual > /dev/null; then
-    echo "     PASS"
-else
-    echo "     FAIL"
-    echo "     Expected output: See file dump.expected"
-    echo "     Actual output:   See file dump.actual"
-fi
+pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
 
 printf " Restore with nothing to do...\t\t\t"
 $NOTMUCH restore dump.expected
-echo " PASS"
+pass_if_equal "$?" "0"
 
 printf "\nTesting threading when messages received out of order:\n"
 printf " Adding initial child message...\t\t"
@@ -635,9 +814,17 @@ printf " Searching returns all three messages in one thread..."
 output=$($NOTMUCH search foo | notmuch_search_sanitize)
 pass_if_equal "$output" "thread:XXX   2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
 
-cat <<EOF
-Notmuch test suite complete.
+echo ""
+echo "Notmuch test suite complete."
 
-Intermediate state can be examined in:
-       ${TEST_DIR}
-EOF
+if [ "$test_failures" = "0" ]; then
+    echo "All $tests tests passed."
+    rm -rf ${TEST_DIR}
+else
+    echo "$test_failures/$tests tests failed. The failures can be investigated in:"
+    echo "${TEST_DIR}"
+fi
+
+echo ""
+
+exit $test_failures