[PATCH 4/4] Tests for maildir synchronization

2010-10-13 Thread Michal Sojka
Signed-off-by: Michal Sojka 
---
 test/maildir-sync |  216 +
 test/notmuch-test |2 +-
 test/test-lib.sh  |   14 +++-
 3 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100755 test/maildir-sync

diff --git a/test/maildir-sync b/test/maildir-sync
new file mode 100755
index 000..a5f8c36
--- /dev/null
+++ b/test/maildir-sync
@@ -0,0 +1,216 @@
+#!/bin/bash
+
+test_description="Test maildir synchronization"
+
+. ./test-lib.sh
+
+filter_show() {
+sed -e 's/, /,\n/g'|sed -e "s|${MAIL_DIR}/||" -e '/^"tags"/d'
+echo
+}
+
+cat >> "$NOTMUCH_CONFIG" < expected < actual &&
+test_cmp expected actual
+#emacs --eval "(gdb \"gdb --annotate=3 --args $(which notmuch) new\")"
+'
+cat > expected < actual &&
+test_cmp expected actual
+'
+cat > expected < actual &&
+test_cmp expected actual
+'
+cat > expected < actual 
&&
+test_cmp expected actual
+'
+cat > expected < actual &&
+test_cmp expected actual
+'
+cat > expected < actual 
&&
+test_cmp expected actual
+'
+test_expect_success 'Tag the seen messages as replied' '
+notmuch tag +replied -inbox tag:inbox and not tag:unread
+'
+
+cat > expected < actual &&
+test_cmp expected actual
+'
+cat < show-expected
+[[[{"id": "msg-001 at notmuch-test-suite",
+"match": true,
+"filename": "msg-001:2,RS",
+"timestamp": 946728000,
+"date_relative": "2000-01-01",
+"headers": {"Subject": "test message",
+"From": "Notmuch Test Suite ",
+"To": "Notmuch Test Suite ",
+"Cc": "",
+"Bcc": "",
+"Date": "Sat,
+01 Jan 2000 12:00:00 -"},
+"body": [{"id": 1,
+"content-type": "text/plain",
+"content": "This is just a test message (#1)\n"}]},
+[
+EOF
+
+test_expect_success 'Renamed message can be shown without running notmuch new' 
'
+notmuch show --format=json id:msg-001 at notmuch-test-suite | filter_show > 
show-actual &&
+test_cmp show-expected show-actual
+'
+
+test_expect_success 'Test that we can reply to the renamed message' '
+notmuch reply id:msg-001 at notmuch-test-suite
+'
+
+echo "No new mail." > expected
+test_expect_success 'No rename should be detected by notmuch new' '
+increment_mtime "$(dirname "${gen_msg_filename}")" &&
+notmuch new > actual &&
+test_cmp expected actual
+'
+test_expect_success "Add a message to new/ without info" '
+generate_message [subject]="\"test message 3\"" [date]="\"Sat, 01 Jan 2000 
12:00:00 -\"" [dir]=new &&
+NOTMUCH_NEW > actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < expected &&
+notmuch show id:$gen_msg_id|grep -o "filename:.*$" > actual &&
+test_cmp expected actual &&
+test -f "$gen_msg_filename"
+'
+test_expect_success "Check that the message was not renamed" '
+ls "${MAIL_DIR}/new" > actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual /dev/null
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 5f7fa14..2036669 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -237,6 +237,12 @@ increment_mtime ()
 #  Generate the message in directory 'directory/of/choice' within
 #  the mail store. The directory will be created if necessary.
 #
+#  [filename]=name
+#
+#  Store the message in file 'name'. The default is to store it
+#  in 'msg-', where  is three-digit number of the
+#  message.
+#  
 #  [body]=text
 #
 #  Text to use as the body of the email message
@@ -273,10 +279,14 @@ generate_message ()
 local additional_headers

 gen_msg_cnt=$((gen_msg_cnt + 1))
-gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
+if [ -z "${template[filename]}" ]; then
+   gen_msg_name="msg-$(printf "%03d" $gen_msg_cnt)"
+else
+   gen_msg_name=${template[filename]}
+fi

 if [ -z "${template[id]}" ]; then
-   gen_msg_id="${gen_msg_name}@notmuch-test-suite"
+   gen_msg_id="${gen_msg_name%:2,*}@notmuch-test-suite"
 else
gen_msg_id="${template[id]}"
 fi
-- 
1.7.1.3.g75e44



[PATCH 4/4] Tests for maildir synchronization

2010-10-13 Thread Michal Sojka
Signed-off-by: Michal Sojka sojk...@fel.cvut.cz
---
 test/maildir-sync |  216 +
 test/notmuch-test |2 +-
 test/test-lib.sh  |   14 +++-
 3 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100755 test/maildir-sync

diff --git a/test/maildir-sync b/test/maildir-sync
new file mode 100755
index 000..a5f8c36
--- /dev/null
+++ b/test/maildir-sync
@@ -0,0 +1,216 @@
+#!/bin/bash
+
+test_description=Test maildir synchronization
+
+. ./test-lib.sh
+
+filter_show() {
+sed -e 's/, /,\n/g'|sed -e s|${MAIL_DIR}/|| -e '/^tags/d'
+echo
+}
+
+cat  $NOTMUCH_CONFIG EOF
+[maildir]
+sync_level=4
+EOF
+
+test_begin_subtest No new messages
+output=$(NOTMUCH_NEW)
+test_expect_equal $output No new mail.
+
+cat  expected EOF
+Added 1 new message to the database.
+EOF
+test_expect_success Add a message, no flags '
+generate_message [subject]=\test message\ [date]=\Sat, 01 Jan 2000 
12:00:00 -\ [filename]=\msg-001:2,\ 
+NOTMUCH_NEW  actual 
+test_cmp expected actual
+#emacs --eval (gdb \gdb --annotate=3 --args $(which notmuch) new\)
+'
+cat  expected EOF
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox unread)
+EOF
+test_expect_success 'Search for the message' '
+notmuch search tag:inbox and tag:unread | notmuch_search_sanitize  actual 
+test_cmp expected actual
+'
+cat  expected EOF
+No new mail. Detected 1 file rename.
+EOF
+test_expect_success 'Add seen flag' '
+mv ${gen_msg_filename} ${gen_msg_filename}S 
+increment_mtime $(dirname ${gen_msg_filename}) 
+NOTMUCH_NEW  actual 
+test_cmp expected actual
+'
+cat  expected EOF
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)
+EOF
+test_expect_success 'Check that tags were updated' '
+notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize  actual 

+test_cmp expected actual
+'
+cat  expected EOF
+Added 1 new message to the database.
+EOF
+test_expect_success Add a seen message '
+generate_message [subject]=\test message 2\ [date]=\Sat, 01 Jan 2000 
12:00:00 -\ [filename]=\msg-002:2,S\ 
+NOTMUCH_NEW  actual 
+test_cmp expected actual
+'
+cat  expected EOF
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 2 (inbox)
+EOF
+test_expect_success 'Check that the seen message is not tagged unread' '
+notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize  actual 

+test_cmp expected actual
+'
+test_expect_success 'Tag the seen messages as replied' '
+notmuch tag +replied -inbox tag:inbox and not tag:unread
+'
+
+cat  expected EOF
+msg-001:2,RS
+msg-002:2,RS
+EOF
+test_expect_success 'Check that R flag was added' '
+ls -1 ${MAIL_DIR}  actual 
+test_cmp expected actual
+'
+cat EOF  show-expected
+[[[{id: msg-...@notmuch-test-suite,
+match: true,
+filename: msg-001:2,RS,
+timestamp: 946728000,
+date_relative: 2000-01-01,
+headers: {Subject: test message,
+From: Notmuch Test Suite test_su...@notmuchmail.org,
+To: Notmuch Test Suite test_su...@notmuchmail.org,
+Cc: ,
+Bcc: ,
+Date: Sat,
+01 Jan 2000 12:00:00 -},
+body: [{id: 1,
+content-type: text/plain,
+content: This is just a test message (#1)\n}]},
+[
+EOF
+
+test_expect_success 'Renamed message can be shown without running notmuch new' 
'
+notmuch show --format=json id:msg-...@notmuch-test-suite | filter_show  
show-actual 
+test_cmp show-expected show-actual
+'
+
+test_expect_success 'Test that we can reply to the renamed message' '
+notmuch reply id:msg-...@notmuch-test-suite
+'
+
+echo No new mail.  expected
+test_expect_success 'No rename should be detected by notmuch new' '
+increment_mtime $(dirname ${gen_msg_filename}) 
+notmuch new  actual 
+test_cmp expected actual
+'
+test_expect_success Add a message to new/ without info '
+generate_message [subject]=\test message 3\ [date]=\Sat, 01 Jan 2000 
12:00:00 -\ [dir]=new 
+NOTMUCH_NEW  actual 
+test_cmp - actual EOF
+Added 1 new message to the database.
+EOF
+'
+test_expect_success Check that the message has inbox and unread tags '
+notmuch search tag:inbox and tag:unread | notmuch_search_sanitize  actual 
+test_cmp - actual EOF
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox unread)
+EOF
+'
+test_expect_success Tag the message with 'tmp' tag '
+notmuch tag +tmp tag:inbox and tag:unread'
+
+test_expect_success Check that the message was not moved from new/ to cur/ '
+echo filename:$gen_msg_filename  expected 
+notmuch show id:$gen_msg_id|grep -o filename:.*$  actual 
+test_cmp expected actual 
+test -f $gen_msg_filename
+'
+test_expect_success Check that the message was not renamed '
+ls ${MAIL_DIR}/new  actual 
+test_cmp - actual EOF
+msg-003
+EOF
+'
+test_expect_success 'Removing of unread tag should fail without cur/' '
+test_must_fail notmuch tag -unread tag:inbox and tag:unread
+'
+test_expect_success Check that the tags were not changed '
+notmuch search tag:inbox and tag:unread | 

[PATCH 4/4] Tests for maildir synchronization

2010-05-11 Thread Michal Sojka
Signed-off-by: Michal Sojka 
---
 test/t0011-maildir-sync.sh |  216 
 test/test-lib.sh   |   11 ++-
 2 files changed, 223 insertions(+), 4 deletions(-)
 create mode 100755 test/t0011-maildir-sync.sh

diff --git a/test/t0011-maildir-sync.sh b/test/t0011-maildir-sync.sh
new file mode 100755
index 000..6bdee2d
--- /dev/null
+++ b/test/t0011-maildir-sync.sh
@@ -0,0 +1,216 @@
+#!/bin/bash
+
+test_description="Test maildir synchronization"
+
+. ./test-lib.sh
+
+filter_show() {
+sed -e 's/, /,\n/g'|sed -e "s|${MAIL_DIR}/||" -e '/^"tags"/d'
+echo
+}
+
+cat >> "$NOTMUCH_CONFIG" < expected < actual &&
+test_cmp expected actual
+#emacs --eval "(gdb \"gdb --annotate=3 --args $(which notmuch) new\")"
+'
+cat > expected < actual &&
+test_cmp expected actual
+'
+cat > expected < actual &&
+test_cmp expected actual
+'
+cat > expected < actual 
&&
+test_cmp expected actual
+'
+cat > expected < actual &&
+test_cmp expected actual
+'
+cat > expected < actual 
&&
+test_cmp expected actual
+'
+test_expect_success 'Tag the seen messages as replied' '
+notmuch tag +replied -inbox tag:inbox and not tag:unread
+'
+
+cat > expected < actual &&
+test_cmp expected actual
+'
+cat < show-expected
+[[[{"id": "msg-001 at notmuch-test-suite",
+"match": true,
+"filename": "msg-001:2,RS",
+"timestamp": 946728000,
+"date_relative": "2000-01-01",
+"headers": {"Subject": "test message",
+"From": "Notmuch Test Suite ",
+"To": "Notmuch Test Suite ",
+"Cc": "",
+"Bcc": "",
+"Date": "Sat,
+01 Jan 2000 12:00:00 -"},
+"body": [{"id": 1,
+"content-type": "text/plain",
+"content": "This is just a test message (#1)\n"}]},
+[
+EOF
+
+test_expect_success 'Renamed message can be shown without running notmuch new' 
'
+notmuch show --format=json id:msg-001 at notmuch-test-suite | filter_show > 
show-actual &&
+test_cmp show-expected show-actual
+'
+
+test_expect_success 'Test that we can reply to the renamed message' '
+notmuch reply id:msg-001 at notmuch-test-suite
+'
+
+echo "No new mail." > expected
+test_expect_success 'No rename should be detected by notmuch new' '
+increment_mtime "$(dirname "${gen_msg_filename}")" &&
+notmuch new > actual &&
+test_cmp expected actual
+'
+test_expect_success "Add a message to new/ without info" '
+generate_message [subject]="\"test message 3\"" [date]="\"Sat, 01 Jan 2000 
12:00:00 -\"" [dir]=new &&
+NOTMUCH_NEW > actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < expected &&
+notmuch show id:$gen_msg_id|grep -o "filename:.*$" > actual &&
+test_cmp expected actual &&
+test -f "$gen_msg_filename"
+'
+test_expect_success "Check that the message was not renamed" '
+ls "${MAIL_DIR}/new" > actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual < actual &&
+test_cmp - actual <

[PATCH 4/4] Tests for maildir synchronization

2010-05-11 Thread Michal Sojka
Signed-off-by: Michal Sojka sojk...@fel.cvut.cz
---
 test/t0011-maildir-sync.sh |  216 
 test/test-lib.sh   |   11 ++-
 2 files changed, 223 insertions(+), 4 deletions(-)
 create mode 100755 test/t0011-maildir-sync.sh

diff --git a/test/t0011-maildir-sync.sh b/test/t0011-maildir-sync.sh
new file mode 100755
index 000..6bdee2d
--- /dev/null
+++ b/test/t0011-maildir-sync.sh
@@ -0,0 +1,216 @@
+#!/bin/bash
+
+test_description=Test maildir synchronization
+
+. ./test-lib.sh
+
+filter_show() {
+sed -e 's/, /,\n/g'|sed -e s|${MAIL_DIR}/|| -e '/^tags/d'
+echo
+}
+
+cat  $NOTMUCH_CONFIG EOF
+[maildir]
+sync_level=4
+EOF
+
+test_expect_success No new mail '
+output=$(NOTMUCH_NEW) 
+pass_if_equal $output No new mail.
+'
+cat  expected EOF
+Added 1 new message to the database.
+EOF
+test_expect_success Add a message, no flags '
+generate_message [subject]=\test message\ [date]=\Sat, 01 Jan 2000 
12:00:00 -\ [filename]=\msg-001:2,\ 
+NOTMUCH_NEW  actual 
+test_cmp expected actual
+#emacs --eval (gdb \gdb --annotate=3 --args $(which notmuch) new\)
+'
+cat  expected EOF
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox unread)
+EOF
+test_expect_success 'Search for the message' '
+notmuch search tag:inbox and tag:unread | notmuch_search_sanitize  actual 
+test_cmp expected actual
+'
+cat  expected EOF
+No new mail. Detected 1 file rename.
+EOF
+test_expect_success 'Add seen flag' '
+mv ${gen_msg_filename} ${gen_msg_filename}S 
+increment_mtime $(dirname ${gen_msg_filename}) 
+NOTMUCH_NEW  actual 
+test_cmp expected actual
+'
+cat  expected EOF
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)
+EOF
+test_expect_success 'Check that tags were updated' '
+notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize  actual 

+test_cmp expected actual
+'
+cat  expected EOF
+Added 1 new message to the database.
+EOF
+test_expect_success Add a seen message '
+generate_message [subject]=\test message 2\ [date]=\Sat, 01 Jan 2000 
12:00:00 -\ [filename]=\msg-002:2,S\ 
+NOTMUCH_NEW  actual 
+test_cmp expected actual
+'
+cat  expected EOF
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 2 (inbox)
+EOF
+test_expect_success 'Check that the seen message is not tagged unread' '
+notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize  actual 

+test_cmp expected actual
+'
+test_expect_success 'Tag the seen messages as replied' '
+notmuch tag +replied -inbox tag:inbox and not tag:unread
+'
+
+cat  expected EOF
+msg-001:2,RS
+msg-002:2,RS
+EOF
+test_expect_success 'Check that R flag was added' '
+ls -1 ${MAIL_DIR}  actual 
+test_cmp expected actual
+'
+cat EOF  show-expected
+[[[{id: msg-...@notmuch-test-suite,
+match: true,
+filename: msg-001:2,RS,
+timestamp: 946728000,
+date_relative: 2000-01-01,
+headers: {Subject: test message,
+From: Notmuch Test Suite test_su...@notmuchmail.org,
+To: Notmuch Test Suite test_su...@notmuchmail.org,
+Cc: ,
+Bcc: ,
+Date: Sat,
+01 Jan 2000 12:00:00 -},
+body: [{id: 1,
+content-type: text/plain,
+content: This is just a test message (#1)\n}]},
+[
+EOF
+
+test_expect_success 'Renamed message can be shown without running notmuch new' 
'
+notmuch show --format=json id:msg-...@notmuch-test-suite | filter_show  
show-actual 
+test_cmp show-expected show-actual
+'
+
+test_expect_success 'Test that we can reply to the renamed message' '
+notmuch reply id:msg-...@notmuch-test-suite
+'
+
+echo No new mail.  expected
+test_expect_success 'No rename should be detected by notmuch new' '
+increment_mtime $(dirname ${gen_msg_filename}) 
+notmuch new  actual 
+test_cmp expected actual
+'
+test_expect_success Add a message to new/ without info '
+generate_message [subject]=\test message 3\ [date]=\Sat, 01 Jan 2000 
12:00:00 -\ [dir]=new 
+NOTMUCH_NEW  actual 
+test_cmp - actual EOF
+Added 1 new message to the database.
+EOF
+'
+test_expect_success Check that the message has inbox and unread tags '
+notmuch search tag:inbox and tag:unread | notmuch_search_sanitize  actual 
+test_cmp - actual EOF
+thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox unread)
+EOF
+'
+test_expect_success Tag the message with 'tmp' tag '
+notmuch tag +tmp tag:inbox and tag:unread'
+
+test_expect_success Check that the message was not moved from new/ to cur/ '
+echo filename:$gen_msg_filename  expected 
+notmuch show id:$gen_msg_id|grep -o filename:.*$  actual 
+test_cmp expected actual 
+test -f $gen_msg_filename
+'
+test_expect_success Check that the message was not renamed '
+ls ${MAIL_DIR}/new  actual 
+test_cmp - actual EOF
+msg-003
+EOF
+'
+test_expect_success 'Removing of unread tag should fail without cur/' '
+test_must_fail notmuch tag -unread tag:inbox and tag:unread
+'
+test_expect_success Check that the tags were not changed '
+notmuch search tag:inbox and tag:unread |