[PATCH 4/4] Tests for maildir synchronization
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 11 May 2010 12:14:21 +0000 (14:14 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:02 +0000 (09:37 -0800)
a2/a0dfed375b2d4a1b3d14703183c31994a59c48 [new file with mode: 0644]

diff --git a/a2/a0dfed375b2d4a1b3d14703183c31994a59c48 b/a2/a0dfed375b2d4a1b3d14703183c31994a59c48
new file mode 100644 (file)
index 0000000..ba66fe3
--- /dev/null
@@ -0,0 +1,315 @@
+Return-Path: <sojkam1@fel.cvut.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 33D58409DE6\r
+       for <notmuch@notmuchmail.org>; Tue, 11 May 2010 05:15:16 -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=ham\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 uh08dxlZQ6-d for <notmuch@notmuchmail.org>;\r
+       Tue, 11 May 2010 05:15:01 -0700 (PDT)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id 4F782418C25\r
+       for <notmuch@notmuchmail.org>; Tue, 11 May 2010 05:14:38 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.4])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id A2CC819F33F8;\r
+       Tue, 11 May 2010 14:14:37 +0200 (CEST)\r
+X-Virus-Scanned: IMAP AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+       by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
+       port 10044)\r
+       with ESMTP id auSlytIHSLgM; Tue, 11 May 2010 14:14:33 +0200 (CEST)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id F28B719F33FB;\r
+       Tue, 11 May 2010 14:14:31 +0200 (CEST)\r
+Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30])\r
+       (Authenticated sender: sojkam1)\r
+       by imap.feld.cvut.cz (Postfix) with ESMTPSA id C22C3FA004;\r
+       Tue, 11 May 2010 14:14:31 +0200 (CEST)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.71)\r
+       (envelope-from <sojkam1@fel.cvut.cz>)\r
+       id 1OBoM3-0005t2-K3; Tue, 11 May 2010 14:14:31 +0200\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/4] Tests for maildir synchronization\r
+Date: Tue, 11 May 2010 14:14:21 +0200\r
+Message-Id: <1273580061-22580-5-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 1.7.1\r
+In-Reply-To: <1273580061-22580-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1273580061-22580-1-git-send-email-sojkam1@fel.cvut.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: Tue, 11 May 2010 12:15:16 -0000\r
+\r
+Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
+---\r
+ test/t0011-maildir-sync.sh |  216 ++++++++++++++++++++++++++++++++++++++++++++\r
+ test/test-lib.sh           |   11 ++-\r
+ 2 files changed, 223 insertions(+), 4 deletions(-)\r
+ create mode 100755 test/t0011-maildir-sync.sh\r
+\r
+diff --git a/test/t0011-maildir-sync.sh b/test/t0011-maildir-sync.sh\r
+new file mode 100755\r
+index 0000000..6bdee2d\r
+--- /dev/null\r
++++ b/test/t0011-maildir-sync.sh\r
+@@ -0,0 +1,216 @@\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
++sync_level=4\r
++EOF\r
++\r
++test_expect_success "No new mail" '\r
++output=$(NOTMUCH_NEW) &&\r
++pass_if_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 'Renamed message 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_done\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 06559cd..3c288a5 100755\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -276,12 +276,15 @@ generate_message ()\r
+     local -A template="($@)"\r
+     local additional_headers\r
\r
++    gen_msg_cnt=$((gen_msg_cnt + 1))\r
++    if [ -z "${template[filename]}" ]; then\r
++      template[filename]="msg-$(printf "%03d" $gen_msg_cnt)"\r
++    fi\r
++    gen_msg_name=${template[filename]}\r
++\r
+     if [ -z "${template[id]}" ]; then\r
+-      gen_msg_cnt=$((gen_msg_cnt + 1))\r
+-      gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)\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_name="msg-${template[id]}"\r
+       gen_msg_id="${template[id]}"\r
+     fi\r
\r
+-- \r
+1.7.1\r
+\r