[PATCH v4 4/4] Tests for maildir synchronization
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 31 Oct 2010 21:29:18 +0000 (22:29 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:20 +0000 (09:37 -0800)
e1/76014a5f0ae4bf7ec336d728dfdd62cfb672f2 [new file with mode: 0644]

diff --git a/e1/76014a5f0ae4bf7ec336d728dfdd62cfb672f2 b/e1/76014a5f0ae4bf7ec336d728dfdd62cfb672f2
new file mode 100644 (file)
index 0000000..48e2cdf
--- /dev/null
@@ -0,0 +1,342 @@
+Return-Path: <wsh@resox.2x.cz>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id CDCB540D16B\r
+       for <notmuch@notmuchmail.org>; Sun, 31 Oct 2010 14:49:04 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.9\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
+       tests=[BAYES_00=-1.9] autolearn=unavailable\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 055PvEuhsgn7 for <notmuch@notmuchmail.org>;\r
+       Sun, 31 Oct 2010 14:48:49 -0700 (PDT)\r
+Received: from smtp.nextra.cz (smtp.nextra.cz [212.65.193.3])\r
+       by olra.theworths.org (Postfix) with ESMTP id 7554240D16C\r
+       for <notmuch@notmuchmail.org>; Sun, 31 Oct 2010 14:48:02 -0700 (PDT)\r
+Received: from resox.2x.cz (unknown [213.29.198.144])\r
+       by smtp.nextra.cz (Postfix) with ESMTP id A3D2188D35;\r
+       Sun, 31 Oct 2010 22:30:36 +0100 (CET)\r
+Received: from wsh by resox.2x.cz with local (Exim 4.72)\r
+       (envelope-from <wsh@resox.2x.cz>)\r
+       id 1PCfTu-0004wr-Dp; Sun, 31 Oct 2010 22:30:26 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 4/4] Tests for maildir synchronization\r
+Date: Sun, 31 Oct 2010 22:29:18 +0100\r
+Message-Id: <1288560558-18915-5-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 1.7.1\r
+In-Reply-To: <87tyk3vpxd.fsf@wsheee.2x.cz>\r
+References: <87tyk3vpxd.fsf@wsheee.2x.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 31 Oct 2010 21:49:05 -0000\r
+\r
+Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
+---\r
+ test/maildir-sync |  231 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ test/notmuch-test |    2 +-\r
+ test/test-lib.sh  |   14 +++-\r
+ 3 files changed, 244 insertions(+), 3 deletions(-)\r
+ create mode 100755 test/maildir-sync\r
+\r
+diff --git a/test/maildir-sync b/test/maildir-sync\r
+new file mode 100755\r
+index 0000000..23d612e\r
+--- /dev/null\r
++++ b/test/maildir-sync\r
+@@ -0,0 +1,231 @@\r
++#!/bin/bash\r
++\r
++test_description="Test maildir synchronization"\r
++\r
++. ./test-lib.sh\r
++\r
++filter_show() {\r
++    sed -e 's/, /,\n/g'|sed -e "s|${MAIL_DIR}/||" -e '/^"tags"/d'\r
++    echo\r
++}\r
++\r
++cat >> "$NOTMUCH_CONFIG" <<EOF\r
++[maildir]\r
++synchronize_flags=true\r
++EOF\r
++\r
++test_begin_subtest "No new messages"\r
++output=$(NOTMUCH_NEW)\r
++test_expect_equal "$output" "No new mail."\r
++\r
++cat > expected <<EOF\r
++Added 1 new message to the database.\r
++EOF\r
++test_expect_success "Add a message, no flags" '\r
++generate_message [subject]="\"test message\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [filename]="\"msg-001:2,\"" &&\r
++NOTMUCH_NEW > actual &&\r
++test_cmp expected actual\r
++#emacs --eval "(gdb \"gdb --annotate=3 --args $(which notmuch) new\")"\r
++'\r
++cat > expected <<EOF\r
++thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox unread)\r
++EOF\r
++test_expect_success 'Search for the message' '\r
++notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
++test_cmp expected actual\r
++'\r
++cat > expected <<EOF\r
++No new mail. Detected 1 file rename.\r
++EOF\r
++test_expect_success 'Add seen flag' '\r
++mv "${gen_msg_filename}" "${gen_msg_filename}S" &&\r
++increment_mtime "$(dirname "${gen_msg_filename}")" &&\r
++NOTMUCH_NEW > actual &&\r
++test_cmp expected actual\r
++'\r
++cat > expected <<EOF\r
++thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)\r
++EOF\r
++test_expect_success 'Check that tags were updated' '\r
++notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize > actual &&\r
++test_cmp expected actual\r
++'\r
++cat > expected <<EOF\r
++Added 1 new message to the database.\r
++EOF\r
++test_expect_success "Add a seen message" '\r
++generate_message [subject]="\"test message 2\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [filename]="\"msg-002:2,S\"" &&\r
++NOTMUCH_NEW > actual &&\r
++test_cmp expected actual\r
++'\r
++cat > expected <<EOF\r
++thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)\r
++thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 2 (inbox)\r
++EOF\r
++test_expect_success 'Check that the seen message is not tagged unread' '\r
++notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize > actual &&\r
++test_cmp expected actual\r
++'\r
++test_expect_success 'Tag the seen messages as replied' '\r
++notmuch tag +replied -inbox tag:inbox and not tag:unread\r
++'\r
++\r
++cat > expected <<EOF\r
++msg-001:2,RS\r
++msg-002:2,RS\r
++EOF\r
++test_expect_success 'Check that R flag was added' '\r
++ls -1 "${MAIL_DIR}" > actual &&\r
++test_cmp expected actual\r
++'\r
++cat <<EOF > show-expected\r
++[[[{"id": "msg-001@notmuch-test-suite",\r
++"match": true,\r
++"filename": "msg-001:2,RS",\r
++"timestamp": 946728000,\r
++"date_relative": "2000-01-01",\r
++"headers": {"Subject": "test message",\r
++"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
++"To": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
++"Cc": "",\r
++"Bcc": "",\r
++"Date": "Sat,\r
++01 Jan 2000 12:00:00 -0000"},\r
++"body": [{"id": 1,\r
++"content-type": "text/plain",\r
++"content": "This is just a test message (#1)\n"}]},\r
++[]]]]\r
++EOF\r
++\r
++test_expect_success 'Message renamed due to changed flags can be shown without running notmuch new' '\r
++notmuch show --format=json id:msg-001@notmuch-test-suite | filter_show > show-actual &&\r
++test_cmp show-expected show-actual\r
++'\r
++\r
++test_expect_success 'Test that we can reply to the renamed message' '\r
++notmuch reply id:msg-001@notmuch-test-suite\r
++'\r
++\r
++echo "No new mail." > expected\r
++test_expect_success 'No rename should be detected by notmuch new' '\r
++increment_mtime "$(dirname "${gen_msg_filename}")" &&\r
++notmuch new > actual &&\r
++test_cmp expected actual\r
++'\r
++test_expect_success "Add a message to new/ without info" '\r
++generate_message [subject]="\"test message 3\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [dir]=new &&\r
++NOTMUCH_NEW > actual &&\r
++test_cmp - actual <<EOF\r
++Added 1 new message to the database.\r
++EOF\r
++'\r
++test_expect_success "Check that the message has inbox and unread tags" '\r
++notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
++test_cmp - actual <<EOF\r
++thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox unread)\r
++EOF\r
++'\r
++test_expect_success "Tag the message with 'tmp' tag" '\r
++notmuch tag +tmp tag:inbox and tag:unread'\r
++\r
++test_expect_success "Check that the message was not moved from new/ to cur/" '\r
++echo filename:$gen_msg_filename > expected &&\r
++notmuch show id:$gen_msg_id|grep -o "filename:.*$" > actual &&\r
++test_cmp expected actual &&\r
++test -f "$gen_msg_filename"\r
++'\r
++test_expect_success "Check that the message was not renamed" '\r
++ls "${MAIL_DIR}/new" > actual &&\r
++test_cmp - actual <<EOF\r
++msg-003\r
++EOF\r
++'\r
++test_expect_success 'Removing of unread tag should fail without cur/' '\r
++test_must_fail notmuch tag -unread tag:inbox and tag:unread\r
++'\r
++test_expect_success "Check that the tags were not changed" '\r
++notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
++test_cmp - actual <<EOF\r
++thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox tmp unread)\r
++EOF\r
++'\r
++\r
++# notmuch new is not necessary here, but we run it in order to check\r
++# for 'no rename' later (*).\r
++test_expect_success 'Create cur/ and let notmuch know about it' '\r
++mkdir "$MAIL_DIR/cur" &&\r
++notmuch new\r
++'\r
++test_expect_success 'Removing of unread tag should pass with cur/' '\r
++notmuch tag -unread tag:inbox and tag:unread\r
++'\r
++test_expect_success 'Check that the message was moved to cur/' '\\r
++ls "$MAIL_DIR/cur" > actual &&\r
++test_cmp - actual <<EOF\r
++msg-003:2,S\r
++EOF\r
++'\r
++test_expect_success 'No rename should be detected by notmuch new' '\r
++increment_mtime "$MAIL_DIR/cur" &&\r
++notmuch new > actual &&\r
++test_cmp - actual <<EOF\r
++No new mail.\r
++EOF\r
++'\r
++# (*) If notmuch new was not run we've got "Processed 1 file in almost\r
++# no time" here. The reason is that removing unread tag in a previous\r
++# test created directory document in the database but this document\r
++# was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new\r
++# could not reach the cur/ directory and its files in it during\r
++# recurive traversal.\r
++test_expect_success 'Remove info from file name' '\r
++mv "$MAIL_DIR/cur/msg-003:2,S" "$MAIL_DIR/cur/msg-003" &&\r
++increment_mtime "$MAIL_DIR/cur" &&\r
++NOTMUCH_NEW > actual\r
++test_cmp - actual <<EOF\r
++No new mail. Detected 1 file rename.\r
++EOF\r
++'\r
++test_expect_success "Check that removing info did not change tags" '\r
++notmuch search tag:inbox | notmuch_search_sanitize > actual &&\r
++test_cmp - actual <<EOF\r
++thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox tmp)\r
++EOF\r
++'\r
++test_expect_success "Add a message to fakenew/ without info" '\r
++generate_message [subject]="\"test message 4\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [dir]=fakenew &&\r
++NOTMUCH_NEW > actual &&\r
++test_cmp - actual <<EOF\r
++Added 1 new message to the database.\r
++EOF\r
++'\r
++test_expect_success "Check that the message has inbox and unread tags" '\r
++notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
++test_cmp - actual <<EOF\r
++thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 4 (inbox unread)\r
++EOF\r
++'\r
++test_expect_success 'Removing of unread tag should leave the message in fakenew/' '\r
++notmuch tag -unread tag:inbox and tag:unread &&\r
++ls "$MAIL_DIR/fakenew" > actual &&\r
++test_cmp - actual <<EOF\r
++msg-004:2,S\r
++EOF\r
++'\r
++\r
++test_expect_success 'Make maildir flags out of sync with the database' '\r
++ls $MAIL_DIR > expected &&\r
++mv $MAIL_DIR/msg-001:2,RS $MAIL_DIR/msg-001:2, &&\r
++mv $MAIL_DIR/msg-002:2,RS $MAIL_DIR/msg-002:2, &&\r
++increment_mtime $MAIL_DIR\r
++'\r
++\r
++test_expect_success 'Test whether dump/new/restore synchronizes the maildir flags with the database' '\r
++notmuch dump dump.txt &&\r
++notmuch new &&\r
++notmuch restore dump.txt &&\r
++ls $MAIL_DIR > actual &&\r
++test_cmp expected actual\r
++'\r
++\r
++test_done\r
+diff --git a/test/notmuch-test b/test/notmuch-test\r
+index 60c3ecb..3691f0d 100755\r
+--- a/test/notmuch-test\r
++++ b/test/notmuch-test\r
+@@ -16,7 +16,7 @@ fi\r
\r
+ cd $(dirname "$0")\r
\r
+-TESTS="basic new search json thread-naming reply dump-restore uuencode thread-order author-order from-guessing long-id encoding emacs"\r
++TESTS="basic new search json thread-naming reply dump-restore uuencode thread-order author-order from-guessing long-id encoding emacs maildir-sync"\r
\r
+ # Clean up any results from a previous run\r
+ rm -r test-results >/dev/null 2>/dev/null\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 8f39aa7..43a1314 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -245,6 +245,12 @@ increment_mtime ()\r
+ #     Generate the message in directory 'directory/of/choice' within\r
+ #     the mail store. The directory will be created if necessary.\r
+ #\r
++#  [filename]=name\r
++#\r
++#     Store the message in file 'name'. The default is to store it\r
++#     in 'msg-<count>', where <count> is three-digit number of the\r
++#     message.\r
++#     \r
+ #  [body]=text\r
+ #\r
+ #     Text to use as the body of the email message\r
+@@ -281,10 +287,14 @@ generate_message ()\r
+     local additional_headers\r
\r
+     gen_msg_cnt=$((gen_msg_cnt + 1))\r
+-    gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)\r
++    if [ -z "${template[filename]}" ]; then\r
++      gen_msg_name="msg-$(printf "%03d" $gen_msg_cnt)"\r
++    else\r
++      gen_msg_name=${template[filename]}\r
++    fi\r
\r
+     if [ -z "${template[id]}" ]; then\r
+-      gen_msg_id="${gen_msg_name}@notmuch-test-suite"\r
++      gen_msg_id="${gen_msg_name%:2,*}@notmuch-test-suite"\r
+     else\r
+       gen_msg_id="${template[id]}"\r
+     fi\r
+-- \r
+1.7.1\r
+\r