+pass_if_equal "$?" "0"
+
+printf "\nTesting threading when messages received out of order:\n"
+printf " Adding initial child message...\t\t"
+generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
+output=$(NOTMUCH_NEW)
+pass_if_equal "$output" "Added 1 new message to the database."
+printf " Searching returns the message...\t\t"
+output=$($NOTMUCH search foo | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
+printf " Adding second child message...\t\t\t"
+generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
+output=$(NOTMUCH_NEW)
+pass_if_equal "$output" "Added 1 new message to the database."
+printf " Searching returns both messages in one thread..."
+output=$($NOTMUCH search foo | notmuch_search_sanitize)
+pass_if_equal "$output" "thread:XXX 2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
+printf " Adding parent message...\t\t\t"
+generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
+output=$(NOTMUCH_NEW)
+pass_if_equal "$output" "Added 1 new message to the database."
+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)"
+
+echo ""
+echo "Notmuch test suite complete."
+
+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