aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Bremner <bremner@debian.org>2012-01-27 18:04:44 -0400
committerDavid Bremner <bremner@debian.org>2012-01-27 18:04:44 -0400
commitbcd44490684965082e5921d0fc71064af3170987 (patch)
tree12506f79f6792236b95ef0d6a19ab5113bb4587d /test
parentbfb7feb1f51ae348503046823d72348621e34d08 (diff)
parentffce9b7c25b9b44ec026b67d96e44cae09c99efe (diff)
Merge commit 'debian/0.11-1' into squeeze-backports
Conflicts: debian/changelog
Diffstat (limited to 'test')
-rw-r--r--test/.gitignore2
-rw-r--r--test/Makefile.local17
-rw-r--r--test/README19
-rw-r--r--test/arg-test.c52
-rwxr-xr-xtest/argument-parsing16
-rwxr-xr-xtest/atomicity12
-rwxr-xr-xtest/basic14
-rwxr-xr-xtest/emacs131
-rw-r--r--test/emacs.expected-output/emacs-stashing9
-rw-r--r--test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation215
-rw-r--r--test/emacs.expected-output/notmuch-show-thread-maildir-storage-without-indentation215
-rwxr-xr-xtest/hooks104
-rwxr-xr-xtest/json2
-rwxr-xr-xtest/notmuch-test7
-rwxr-xr-xtest/python6
-rwxr-xr-xtest/raw2
-rwxr-xr-xtest/symbol-hiding11
-rw-r--r--test/symbol-test.cc14
-rw-r--r--test/test-lib.el15
-rw-r--r--[-rwxr-xr-x]test/test-lib.sh165
20 files changed, 939 insertions, 89 deletions
diff --git a/test/.gitignore b/test/.gitignore
index 9e97052d..e63c689d 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,4 +1,6 @@
test-results
corpus.mail
smtp-dummy
+symbol-test
+arg-test
tmp.*
diff --git a/test/Makefile.local b/test/Makefile.local
index 8eb04330..fa2df734 100644
--- a/test/Makefile.local
+++ b/test/Makefile.local
@@ -2,19 +2,32 @@
dir := test
+extra_cflags += -I.
+
smtp_dummy_srcs = \
$(notmuch_compat_srcs) \
$(dir)/smtp-dummy.c
smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)
+$(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a
+ $(call quiet,CC) -I. $^ -o $@
+
$(dir)/smtp-dummy: $(smtp_dummy_modules)
$(call quiet,CC) $^ -o $@
+$(dir)/symbol-test: $(dir)/symbol-test.o
+ $(call quiet,CXX) $^ -o $@ -Llib -lnotmuch -lxapian
+
.PHONY: test check
-test: all $(dir)/smtp-dummy
+
+test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test
+
+test: all test-binaries
@${dir}/notmuch-test $(OPTIONS)
check: test
-CLEAN := $(CLEAN) $(dir)/smtp-dummy
+CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
+ $(dir)/symbol-test $(dir)/symbol-test.o \
+ $(dir)/arg-test $(dir)/arg-test.o
diff --git a/test/README b/test/README
index 2481f16d..7b2e96d4 100644
--- a/test/README
+++ b/test/README
@@ -13,7 +13,8 @@ notmuch-test script). Either command will run all available tests.
Alternately, you can run a specific subset of tests by simply invoking
one of the executable scripts in this directory, (such as ./search,
-./reply, etc.)
+./reply, etc). Note that you will probably want "make test-binaries"
+before running individual tests.
The following command-line options are available when running tests:
@@ -187,8 +188,8 @@ library for your script to use.
is to summarize successes and failures in the test script and
exit with an appropriate error code.
-There are also a number of mail-specific functions which are useful in
-writing tests:
+There are also a number of notmuch-specific auxiliary functions and
+variables which are useful in writing tests:
generate_message
@@ -212,3 +213,15 @@ writing tests:
will initialize the mail database to a known state of 50 sample
messages, (culled from the early history of the notmuch mailing
list).
+
+ notmuch_counter_reset
+ $notmuch_counter_command
+ notmuch_counter_value
+
+ These allow to count how many times notmuch binary is called.
+ notmuch_counter_reset() function generates a script that counts
+ how many times it is called and resets the counter to zero. The
+ function sets $notmuch_counter_command variable to the path to the
+ generated script that should be called instead of notmuch to do
+ the counting. The notmuch_counter_value() function prints the
+ current counter value.
diff --git a/test/arg-test.c b/test/arg-test.c
new file mode 100644
index 00000000..adc56e30
--- /dev/null
+++ b/test/arg-test.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include "command-line-arguments.h"
+
+
+int main(int argc, char **argv){
+
+ int opt_index=1;
+
+ int kw_val=0;
+ int int_val=0;
+ char *pos_arg1=NULL;
+ char *pos_arg2=NULL;
+ char *string_val=NULL;
+
+ notmuch_opt_desc_t options[] = {
+ { NOTMUCH_OPT_KEYWORD, &kw_val, "keyword", 'k',
+ (notmuch_keyword_t []){ { "one", 1 },
+ { "two", 2 },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_INT, &int_val, "int", 'i', 0},
+ { NOTMUCH_OPT_STRING, &string_val, "string", 's', 0},
+ { NOTMUCH_OPT_POSITION, &pos_arg1, 0,0, 0},
+ { NOTMUCH_OPT_POSITION, &pos_arg2, 0,0, 0},
+ { 0, 0, 0, 0, 0 } };
+
+ opt_index = parse_arguments(argc, argv, options, 1);
+
+ if (opt_index < 0)
+ return 1;
+
+ if (kw_val)
+ printf("keyword %d\n", kw_val);
+
+ if (int_val)
+ printf("int %d\n", int_val);
+
+ if (string_val)
+ printf("string %s\n", string_val);
+
+ if (pos_arg1)
+ printf("positional arg 1 %s\n", pos_arg1);
+
+ if (pos_arg2)
+ printf("positional arg 2 %s\n", pos_arg1);
+
+
+ for ( ; opt_index < argc ; opt_index ++) {
+ printf("non parsed arg %d = %s\n", opt_index, argv[opt_index]);
+ }
+
+ return 0;
+}
diff --git a/test/argument-parsing b/test/argument-parsing
new file mode 100755
index 00000000..672de0b3
--- /dev/null
+++ b/test/argument-parsing
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+test_description="argument parsing"
+. ./test-lib.sh
+
+test_begin_subtest "sanity check"
+$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 > OUTPUT
+cat <<EOF > EXPECTED
+keyword 1
+int 7
+string foo
+positional arg 1 pos1
+positional arg 2 pos1
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_done
diff --git a/test/atomicity b/test/atomicity
index ad7d4a3c..6df0a00e 100755
--- a/test/atomicity
+++ b/test/atomicity
@@ -7,8 +7,7 @@ test_description='atomicity'
# final database contents should be the same regardless of when (or
# if) it is killed and restarted.
-if which gdb 1>/dev/null 2>&1; then
- test_set_prereq GDB
+if test_require_external_prereq gdb; then
# Create a maildir structure to also stress flag synchronization
mkdir $MAIL_DIR/cur
@@ -91,14 +90,11 @@ if which gdb 1>/dev/null 2>&1; then
i=$(expr $end - 1)
fi
done
-else
- say_color info "%-6s" "WARNING"
- echo " Missing test prerequisite GDB"
-fi
+fi
test_begin_subtest '"notmuch new" is idempotent under arbitrary aborts'
-test_expect_equal_file GDB searchall expectall
+test_expect_equal_file searchall expectall
-test_expect_success GDB "detected $outcount>10 abort points" "test $outcount -gt 10"
+test_expect_success "detected $outcount>10 abort points" "test $outcount -gt 10"
test_done
diff --git a/test/basic b/test/basic
index 38db2baf..d6aed24c 100755
--- a/test/basic
+++ b/test/basic
@@ -51,17 +51,11 @@ test_expect_code 2 'failure to clean up causes the test to fail' '
# Ensure that all tests are being run
test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
-eval $(sed -n -e '/^TESTS="$/,/^"$/p' notmuch-test $TEST_DIRECTORY/notmuch-test)
+eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)
tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
-available=$(ls -1 $TEST_DIRECTORY/ | \
- sed -r -e "/^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test)/d" \
- -e "/^(README|test-lib.sh|test-lib.el|test-results|tmp.*|valgrind|corpus*)/d" \
- -e "/^(emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose|symbol-test.cc)/d" \
- -e "/^(test.expected-output|.*~)/d" \
- -e "/^(gnupg-secret-key.asc)/d" \
- -e "/^(gnupg-secret-key.NOTE)/d" \
- -e "/^(atomicity.gdb)/d" \
- | sort)
+available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \
+ sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \
+ sort)
test_expect_equal "$tests_in_suite" "$available"
EXPECTED=$TEST_DIRECTORY/test.expected-output
diff --git a/test/emacs b/test/emacs
index 75a0a744..f36718e7 100755
--- a/test/emacs
+++ b/test/emacs
@@ -50,6 +50,27 @@ test_emacs "(notmuch-show \"$maildir_storage_thread\")
(test-output)"
test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
+test_begin_subtest "Basic notmuch-show view in emacs default indentation"
+maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
+test_emacs "(let ((notmuch-show-indent-messages-width 1))
+ (notmuch-show \"$maildir_storage_thread\")
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
+
+test_begin_subtest "Basic notmuch-show view in emacs without indentation"
+maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
+test_emacs "(let ((notmuch-show-indent-messages-width 0))
+ (notmuch-show \"$maildir_storage_thread\")
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage-without-indentation
+
+test_begin_subtest "Basic notmuch-show view in emacs with fourfold indentation"
+maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
+test_emacs "(let ((notmuch-show-indent-messages-width 4))
+ (notmuch-show \"$maildir_storage_thread\")
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage-with-fourfold-indentation
+
test_begin_subtest "notmuch-show for message with invalid From"
add_message "[subject]=\"message-with-invalid-from\"" \
"[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""
@@ -369,8 +390,18 @@ test_emacs '(notmuch-show "id:\"bought\"")
(rotate-yank-pointer 1))
(reverse-region (point-min) (point-max))
(test-output)'
-sed -i -e 's/^.*tmp.emacs\/mail.*$/FILENAME/' OUTPUT
-test_expect_equal_file OUTPUT $EXPECTED/emacs-stashing
+cat <<EOF >EXPECTED
+Sat, 01 Jan 2000 12:00:00 -0000
+Some One <someone@somewhere.org>
+Some One Else <notsomeone@somewhere.org>
+Notmuch <notmuch@notmuchmail.org>
+Stash my stashables
+id:"bought"
+bought
+inbox,stashtest
+${gen_msg_filename}
+EOF
+test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Stashing in notmuch-search"
test_emacs '(notmuch-search "id:\"bought\"")
@@ -381,33 +412,7 @@ test_emacs '(notmuch-search "id:\"bought\"")
(yank)
(test-output)'
sed -i -e 's/^thread:.*$/thread:XXX/' OUTPUT
-test_expect_equal $(cat OUTPUT) "thread:XXX"
-
-test_begin_subtest 'Hiding message following HTML part'
-test_subtest_known_broken
-id='html-message@notmuchmail.org'
-emacs_deliver_message \
- 'HTML message' \
- '' \
- "(message-goto-eoh)
- (insert \"Message-ID: <$id>\n\")
- (message-goto-body)
- (mml-insert-part \"text/html\")
- (insert \"<body>This is a test HTML message</body>\")"
-emacs_deliver_message \
- 'Reply to HTML message' \
- 'This is a reply to the test HTML message' \
- "(message-goto-eoh)
- (insert \"In-Reply-To: <$id>\n\")"
-test_emacs "(notmuch-show \"id:$id\") \
- (notmuch-show-next-message) \
- (command-execute (key-binding (kbd \"RET\"))) \
- (test-visible-output)"
-test_emacs "(notmuch-show \"id:$id\") \
- (notmuch-show-next-message) \
- (notmuch-show-toggle-message) \
- (test-visible-output \"EXPECTED\")"
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal "$(cat OUTPUT)" "thread:XXX"
test_begin_subtest 'notmuch-show-advance-and-archive with invisible signature'
message1='id:20091118010116.GC25380@dottiness.seas.harvard.edu'
@@ -441,4 +446,72 @@ test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.
(test-visible-output)'
test_expect_equal_file OUTPUT EXPECTED
+test_begin_subtest "Do not call notmuch for non-inlinable application/mpeg parts"
+id='message-with-application/mpeg-attachment@notmuchmail.org'
+emacs_deliver_message \
+ 'Message with application/mpeg attachment' \
+ '' \
+ "(message-goto-eoh)
+ (insert \"Message-ID: <$id>\n\")
+ (message-goto-body)
+ (mml-insert-part \"application/mpeg\")
+ (insert \"a fake mp3 file\")"
+notmuch_counter_reset
+test_emacs "(let ((notmuch-command \"$notmuch_counter_command\"))
+ (notmuch-show \"id:$id\"))"
+test_expect_equal $(notmuch_counter_value) 1
+
+test_begin_subtest "Do not call notmuch for non-inlinable audio/mpeg parts"
+id='message-with-audio/mpeg-attachment@notmuchmail.org'
+emacs_deliver_message \
+ 'Message with audio/mpeg attachment' \
+ '' \
+ "(message-goto-eoh)
+ (insert \"Message-ID: <$id>\n\")
+ (message-goto-body)
+ (mml-insert-part \"audio/mpeg\")
+ (insert \"a fake mp3 file\")"
+notmuch_counter_reset
+test_emacs "(let ((notmuch-command \"$notmuch_counter_command\"))
+ (notmuch-show \"id:$id\"))"
+test_expect_equal $(notmuch_counter_value) 1
+
+test_begin_subtest "notmuch-hello-mode hook is called"
+counter=$(test_emacs \
+ '(let ((notmuch-hello-mode-hook-counter 0))
+ (kill-buffer "*notmuch-hello*")
+ (notmuch-hello)
+ notmuch-hello-mode-hook-counter)'
+)
+test_expect_equal "$counter" 1
+
+test_begin_subtest "notmuch-hello-mode hook is not called on updates"
+counter=$(test_emacs \
+ '(let ((notmuch-hello-mode-hook-counter 0))
+ (kill-buffer "*notmuch-hello*")
+ (notmuch-hello)
+ (notmuch-hello-update)
+ notmuch-hello-mode-hook-counter)'
+)
+test_expect_equal "$counter" 1
+
+test_begin_subtest "notmuch-hello-refresh hook is called"
+counter=$(test_emacs \
+ '(let ((notmuch-hello-refresh-hook-counter 0))
+ (kill-buffer "*notmuch-hello*")
+ (notmuch-hello)
+ notmuch-hello-refresh-hook-counter)'
+)
+test_expect_equal "$counter" 1
+
+test_begin_subtest "notmuch-hello-refresh hook is called on updates"
+counter=$(test_emacs \
+ '(let ((notmuch-hello-refresh-hook-counter 0))
+ (kill-buffer "*notmuch-hello*")
+ (notmuch-hello)
+ (notmuch-hello-update)
+ notmuch-hello-refresh-hook-counter)'
+)
+test_expect_equal "$counter" 2
+
test_done
diff --git a/test/emacs.expected-output/emacs-stashing b/test/emacs.expected-output/emacs-stashing
deleted file mode 100644
index 49235947..00000000
--- a/test/emacs.expected-output/emacs-stashing
+++ /dev/null
@@ -1,9 +0,0 @@
-Sat, 01 Jan 2000 12:00:00 -0000
-Some One <someone@somewhere.org>
-Some One Else <notsomeone@somewhere.org>
-Notmuch <notmuch@notmuchmail.org>
-Stash my stashables
-id:"bought"
-bought
-inbox,stashtest
-FILENAME
diff --git a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
new file mode 100644
index 00000000..41e2aaa3
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
@@ -0,0 +1,215 @@
+Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-17) (inbox signed)
+Subject: [notmuch] Working with Maildir storage?
+To: notmuch@notmuchmail.org
+Date: Tue, 17 Nov 2009 14:00:54 -0500
+
+[ multipart/mixed ]
+[ multipart/signed ]
+[ text/plain ]
+I saw the LWN article and decided to take a look at notmuch. I'm
+currently using mutt and mairix to index and read a collection of
+Maildir mail folders (around 40,000 messages total).
+
+notmuch indexed the messages without complaint, but my attempt at
+searching bombed out. Running, for example:
+
+ notmuch search storage
+
+Resulted in 4604 lines of errors along the lines of:
+
+ Error opening
+ /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S:
+ Too many open files
+
+I'm curious if this is expected behavior (i.e., notmuch does not work
+with Maildir) or if something else is going on.
+
+Cheers,
+
+[ 5-line signature. Click/Enter to show. ]
+--
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Senior Technologist, Computing and Information Technology
+Harvard University School of Engineering and Applied Sciences
+
+[ application/pgp-signature ]
+[ text/plain ]
+[ 4-line signature. Click/Enter to show. ]
+_______________________________________________
+notmuch mailing list
+notmuch@notmuchmail.org
+http://notmuchmail.org/mailman/listinfo/notmuch
+ Mikhail Gusarov <dottedmag@dottedmag.net> (2009-11-17) (inbox signed unread)
+ Subject: Re: [notmuch] Working with Maildir storage?
+ To: notmuch@notmuchmail.org
+ Date: Wed, 18 Nov 2009 01:02:38 +0600
+
+ [ multipart/mixed ]
+ [ multipart/signed ]
+ [ text/plain ]
+
+ Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did gyre and gimble:
+
+ LK> Resulted in 4604 lines of errors along the lines of:
+
+ LK> Error opening
+ LK> /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S:
+ LK> Too many open files
+
+ See the patch just posted here.
+
+ [ 2-line signature. Click/Enter to show. ]
+ --
+ http://fossarchy.blogspot.com/
+ [ application/pgp-signature ]
+ [ text/plain ]
+ [ 4-line signature. Click/Enter to show. ]
+ _______________________________________________
+ notmuch mailing list
+ notmuch@notmuchmail.org
+ http://notmuchmail.org/mailman/listinfo/notmuch
+ Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-17) (inbox signed unread)
+ Subject: Re: [notmuch] Working with Maildir storage?
+ To: Mikhail Gusarov <dottedmag@dottedmag.net>
+ Cc: notmuch@notmuchmail.org
+ Date: Tue, 17 Nov 2009 15:33:01 -0500
+
+ [ multipart/mixed ]
+ [ multipart/signed ]
+ [ text/plain ]
+ > See the patch just posted here.
+
+ Is the list archived anywhere? The obvious archives
+ (http://notmuchmail.org/pipermail/notmuch/) aren't available, and I
+ think I subscribed too late to get the patch (I only just saw the
+ discussion about it).
+
+ It doesn't look like the patch is in git yet.
+
+ -- Lars
+
+ [ 5-line signature. Click/Enter to show. ]
+ --
+ Lars Kellogg-Stedman <lars@seas.harvard.edu>
+ Senior Technologist, Computing and Information Technology
+ Harvard University School of Engineering and Applied Sciences
+
+ [ application/pgp-signature ]
+ [ text/plain ]
+ [ 4-line signature. Click/Enter to show. ]
+ _______________________________________________
+ notmuch mailing list
+ notmuch@notmuchmail.org
+ http://notmuchmail.org/mailman/listinfo/notmuch
+ Mikhail Gusarov <dottedmag@dottedmag.net> (2009-11-17) (inbox unread)
+ Subject: [notmuch] Working with Maildir storage?
+ To: notmuch@notmuchmail.org
+ Date: Wed, 18 Nov 2009 02:50:48 +0600
+
+
+ Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu did gyre and gimble:
+
+ LK> Is the list archived anywhere? The obvious archives
+ LK> (http://notmuchmail.org/pipermail/notmuch/) aren't available, and I
+ LK> think I subscribed too late to get the patch (I only just saw the
+ LK> discussion about it).
+
+ LK> It doesn't look like the patch is in git yet.
+
+ Just has been pushed
+
+ [ 10-line signature. Click/Enter to show. ]
+ --
+ http://fossarchy.blogspot.com/
+ -------------- next part --------------
+ A non-text attachment was scrubbed...
+ Name: not available
+ Type: application/pgp-signature
+ Size: 834 bytes
+ Desc: not available
+ URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp>
+
+ Keith Packard <keithp@keithp.com> (2009-11-17) (inbox unread)
+ Subject: [notmuch] Working with Maildir storage?
+ To: notmuch@notmuchmail.org
+ Date: Tue, 17 Nov 2009 13:24:13 -0800
+
+ On Tue, 17 Nov 2009 15:33:01 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote:
+ > > See the patch just posted here.
+
+ I've also pushed a slightly more complicated (and complete) fix to my
+ private notmuch repository
+
+ git://keithp.com/git/notmuch
+
+ > Is the list archived anywhere?
+
+ Oops. Looks like Carl's mail server is broken. He's traveling to
+ Barcelona today and so it won't get fixed for a while.
+
+ Thanks to everyone for trying out notmuch!
+
+ -keith
+
+ Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-18) (inbox signed unread)
+ Subject: Re: [notmuch] Working with Maildir storage?
+ To: Keith Packard <keithp@keithp.com>
+ Cc: notmuch@notmuchmail.org
+ Date: Tue, 17 Nov 2009 19:50:40 -0500
+
+ [ multipart/mixed ]
+ [ multipart/signed ]
+ [ text/plain ]
+ > I've also pushed a slightly more complicated (and complete) fix to my
+ > private notmuch repository
+
+ The version of lib/messages.cc in your repo doesn't build because it's
+ missing "#include <stdint.h>" (for the uint32_t on line 466).
+
+ [ 5-line signature. Click/Enter to show. ]
+ --
+ Lars Kellogg-Stedman <lars@seas.harvard.edu>
+ Senior Technologist, Computing and Information Technology
+ Harvard University School of Engineering and Applied Sciences
+
+ [ application/pgp-signature ]
+ [ text/plain ]
+ [ 4-line signature. Click/Enter to show. ]
+ _______________________________________________
+ notmuch mailing list
+ notmuch@notmuchmail.org
+ http://notmuchmail.org/mailman/listinfo/notmuch
+ Carl Worth <cworth@cworth.org> (2009-11-18) (inbox unread)
+ Subject: [notmuch] Working with Maildir storage?
+ To: notmuch@notmuchmail.org
+ Date: Wed, 18 Nov 2009 02:08:10 -0800
+
+ On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote:
+ > I saw the LWN article and decided to take a look at notmuch. I'm
+ > currently using mutt and mairix to index and read a collection of
+ > Maildir mail folders (around 40,000 messages total).
+
+ Welcome, Lars!
+
+ I hadn't even seen that Keith's blog post had been picked up by lwn.net.
+ That's very interesting. So, thanks for coming and trying out notmuch.
+
+ > Error opening
+ > /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S:
+ > Too many open files
+
+ Sadly, the lwn article coincided with me having just introduced this
+ bug, and then getting on a Trans-Atlantic flight. So I fixed the bug
+ fairly quickly, but there was quite a bit of latency before I could push
+ the fix out. It should be fixed now.
+
+ > I'm curious if this is expected behavior (i.e., notmuch does not work
+ > with Maildir) or if something else is going on.
+
+ Notmuch works just fine with maildir---it's one of the things that it
+ likes the best.
+
+ Happy hacking,
+
+ -Carl
+
diff --git a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-without-indentation b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-without-indentation
new file mode 100644
index 00000000..fa2108ef
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-without-indentation
@@ -0,0 +1,215 @@
+Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-17) (inbox signed)
+Subject: [notmuch] Working with Maildir storage?
+To: notmuch@notmuchmail.org
+Date: Tue, 17 Nov 2009 14:00:54 -0500
+
+[ multipart/mixed ]
+[ multipart/signed ]
+[ text/plain ]
+I saw the LWN article and decided to take a look at notmuch. I'm
+currently using mutt and mairix to index and read a collection of
+Maildir mail folders (around 40,000 messages total).
+
+notmuch indexed the messages without complaint, but my attempt at
+searching bombed out. Running, for example:
+
+ notmuch search storage
+
+Resulted in 4604 lines of errors along the lines of:
+
+ Error opening
+ /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S:
+ Too many open files
+
+I'm curious if this is expected behavior (i.e., notmuch does not work
+with Maildir) or if something else is going on.
+
+Cheers,
+
+[ 5-line signature. Click/Enter to show. ]
+--
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Senior Technologist, Computing and Information Technology
+Harvard University School of Engineering and Applied Sciences
+
+[ application/pgp-signature ]
+[ text/plain ]
+[ 4-line signature. Click/Enter to show. ]
+_______________________________________________
+notmuch mailing list
+notmuch@notmuchmail.org
+http://notmuchmail.org/mailman/listinfo/notmuch
+Mikhail Gusarov <dottedmag@dottedmag.net> (2009-11-17) (inbox signed unread)
+Subject: Re: [notmuch] Working with Maildir storage?
+To: notmuch@notmuchmail.org
+Date: Wed, 18 Nov 2009 01:02:38 +0600
+
+[ multipart/mixed ]
+[ multipart/signed ]
+[ text/plain ]
+
+Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did gyre and gimble:
+
+ LK> Resulted in 4604 lines of errors along the lines of:
+
+ LK> Error opening
+ LK> /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S:
+ LK> Too many open files
+
+See the patch just posted here.
+
+[ 2-line signature. Click/Enter to show. ]
+--
+http://fossarchy.blogspot.com/
+[ application/pgp-signature ]
+[ text/plain ]
+[ 4-line signature. Click/Enter to show. ]
+_______________________________________________
+notmuch mailing list
+notmuch@notmuchmail.org
+http://notmuchmail.org/mailman/listinfo/notmuch
+Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-17) (inbox signed unread)
+Subject: Re: [notmuch] Working with Maildir storage?
+To: Mikhail Gusarov <dottedmag@dottedmag.net>
+Cc: notmuch@notmuchmail.org
+Date: Tue, 17 Nov 2009 15:33:01 -0500
+
+[ multipart/mixed ]
+[ multipart/signed ]
+[ text/plain ]
+> See the patch just posted here.
+
+Is the list archived anywhere? The obvious archives
+(http://notmuchmail.org/pipermail/notmuch/) aren't available, and I
+think I subscribed too late to get the patch (I only just saw the
+discussion about it).
+
+It doesn't look like the patch is in git yet.
+
+-- Lars
+
+[ 5-line signature. Click/Enter to show. ]
+--
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Senior Technologist, Computing and Information Technology
+Harvard University School of Engineering and Applied Sciences
+
+[ application/pgp-signature ]
+[ text/plain ]
+[ 4-line signature. Click/Enter to show. ]
+_______________________________________________
+notmuch mailing list
+notmuch@notmuchmail.org
+http://notmuchmail.org/mailman/listinfo/notmuch
+Mikhail Gusarov <dottedmag@dottedmag.net> (2009-11-17) (inbox unread)
+Subject: [notmuch] Working with Maildir storage?
+To: notmuch@notmuchmail.org
+Date: Wed, 18 Nov 2009 02:50:48 +0600
+
+
+Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu did gyre and gimble:
+
+ LK> Is the list archived anywhere? The obvious archives
+ LK> (http://notmuchmail.org/pipermail/notmuch/) aren't available, and I
+ LK> think I subscribed too late to get the patch (I only just saw the
+ LK> discussion about it).
+
+ LK> It doesn't look like the patch is in git yet.
+
+Just has been pushed
+
+[ 10-line signature. Click/Enter to show. ]
+--
+http://fossarchy.blogspot.com/
+-------------- next part --------------
+A non-text attachment was scrubbed...
+Name: not available
+Type: application/pgp-signature
+Size: 834 bytes
+Desc: not available
+URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp>
+
+Keith Packard <keithp@keithp.com> (2009-11-17) (inbox unread)
+Subject: [notmuch] Working with Maildir storage?
+To: notmuch@notmuchmail.org
+Date: Tue, 17 Nov 2009 13:24:13 -0800
+
+On Tue, 17 Nov 2009 15:33:01 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote:
+> > See the patch just posted here.
+
+I've also pushed a slightly more complicated (and complete) fix to my
+private notmuch repository
+
+git://keithp.com/git/notmuch
+
+> Is the list archived anywhere?
+
+Oops. Looks like Carl's mail server is broken. He's traveling to
+Barcelona today and so it won't get fixed for a while.
+
+Thanks to everyone for trying out notmuch!
+
+-keith
+
+Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-18) (inbox signed unread)
+Subject: Re: [notmuch] Working with Maildir storage?
+To: Keith Packard <keithp@keithp.com>
+Cc: notmuch@notmuchmail.org
+Date: Tue, 17 Nov 2009 19:50:40 -0500
+
+[ multipart/mixed ]
+[ multipart/signed ]
+[ text/plain ]
+> I've also pushed a slightly more complicated (and complete) fix to my
+> private notmuch repository
+
+The version of lib/messages.cc in your repo doesn't build because it's
+missing "#include <stdint.h>" (for the uint32_t on line 466).
+
+[ 5-line signature. Click/Enter to show. ]
+--
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Senior Technologist, Computing and Information Technology
+Harvard University School of Engineering and Applied Sciences
+
+[ application/pgp-signature ]
+[ text/plain ]
+[ 4-line signature. Click/Enter to show. ]
+_______________________________________________
+notmuch mailing list
+notmuch@notmuchmail.org
+http://notmuchmail.org/mailman/listinfo/notmuch
+Carl Worth <cworth@cworth.org> (2009-11-18) (inbox unread)
+Subject: [notmuch] Working with Maildir storage?
+To: notmuch@notmuchmail.org
+Date: Wed, 18 Nov 2009 02:08:10 -0800
+
+On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote:
+> I saw the LWN article and decided to take a look at notmuch. I'm
+> currently using mutt and mairix to index and read a collection of
+> Maildir mail folders (around 40,000 messages total).
+
+Welcome, Lars!
+
+I hadn't even seen that Keith's blog post had been picked up by lwn.net.
+That's very interesting. So, thanks for coming and trying out notmuch.
+
+> Error opening
+> /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S:
+> Too many open files
+
+Sadly, the lwn article coincided with me having just introduced this
+bug, and then getting on a Trans-Atlantic flight. So I fixed the bug
+fairly quickly, but there was quite a bit of latency before I could push
+the fix out. It should be fixed now.
+
+> I'm curious if this is expected behavior (i.e., notmuch does not work
+> with Maildir) or if something else is going on.
+
+Notmuch works just fine with maildir---it's one of the things that it
+likes the best.
+
+Happy hacking,
+
+-Carl
+
diff --git a/test/hooks b/test/hooks
new file mode 100755
index 00000000..77e8569b
--- /dev/null
+++ b/test/hooks
@@ -0,0 +1,104 @@
+#!/usr/bin/env bash
+test_description='hooks'
+. ./test-lib.sh
+
+HOOK_DIR=${MAIL_DIR}/.notmuch/hooks
+
+create_echo_hook () {
+ local TOKEN="${RANDOM}"
+ mkdir -p ${HOOK_DIR}
+ cat <<EOF >"${HOOK_DIR}/${1}"
+#!/bin/sh
+echo "${TOKEN}" > ${3}
+EOF
+ chmod +x "${HOOK_DIR}/${1}"
+ echo "${TOKEN}" > ${2}
+}
+
+create_failing_hook () {
+ mkdir -p ${HOOK_DIR}
+ cat <<EOF >"${HOOK_DIR}/${1}"
+#!/bin/sh
+exit 13
+EOF
+ chmod +x "${HOOK_DIR}/${1}"
+}
+
+rm_hooks () {
+ rm -rf ${HOOK_DIR}
+}
+
+# add a message to generate mail dir and database
+add_message
+
+test_begin_subtest "pre-new is run"
+rm_hooks
+generate_message
+create_echo_hook "pre-new" expected output
+notmuch new > /dev/null
+test_expect_equal_file expected output
+
+test_begin_subtest "post-new is run"
+rm_hooks
+generate_message
+create_echo_hook "post-new" expected output
+notmuch new > /dev/null
+test_expect_equal_file expected output
+
+test_begin_subtest "pre-new is run before post-new"
+rm_hooks
+generate_message
+create_echo_hook "pre-new" pre-new.expected pre-new.output
+create_echo_hook "post-new" post-new.expected post-new.output
+notmuch new > /dev/null
+test_expect_equal_file post-new.expected post-new.output
+
+test_begin_subtest "pre-new non-zero exit status (hook status)"
+rm_hooks
+generate_message
+create_failing_hook "pre-new"
+output=`notmuch new 2>&1`
+test_expect_equal "$output" "Error: pre-new hook failed with status 13"
+
+# depends on the previous subtest leaving broken hook behind
+test_expect_code 1 "pre-new non-zero exit status (notmuch status)" "notmuch new"
+
+# depends on the previous subtests leaving 1 new message behind
+test_begin_subtest "pre-new non-zero exit status aborts new"
+rm_hooks
+output=$(NOTMUCH_NEW)
+test_expect_equal "$output" "Added 1 new message to the database."
+
+test_begin_subtest "post-new non-zero exit status (hook status)"
+rm_hooks
+generate_message
+create_failing_hook "post-new"
+NOTMUCH_NEW 2>output.stderr >output
+cat output.stderr >> output
+echo "Added 1 new message to the database." > expected
+echo "Error: post-new hook failed with status 13" >> expected
+test_expect_equal_file expected output
+
+# depends on the previous subtest leaving broken hook behind
+test_expect_code 1 "post-new non-zero exit status (notmuch status)" "notmuch new"
+
+# test_begin_subtest "hook without executable permissions"
+rm_hooks
+mkdir -p ${HOOK_DIR}
+cat <<EOF >"${HOOK_DIR}/pre-new"
+#!/bin/sh
+echo foo
+EOF
+output=`notmuch new 2>&1`
+test_expect_code 1 "hook without executable permissions" "notmuch new"
+
+# test_begin_subtest "hook execution failure"
+rm_hooks
+mkdir -p ${HOOK_DIR}
+cat <<EOF >"${HOOK_DIR}/pre-new"
+no hashbang, execl fails
+EOF
+chmod +x "${HOOK_DIR}/pre-new"
+test_expect_code 1 "hook execution failure" "notmuch new"
+
+test_done
diff --git a/test/json b/test/json
index 592b0687..7df43803 100755
--- a/test/json
+++ b/test/json
@@ -12,6 +12,7 @@ add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00
output=$(notmuch search --format=json "json-search-message" | notmuch_search_sanitize)
test_expect_equal "$output" "[{\"thread\": \"XXX\",
\"timestamp\": 946728000,
+\"date_relative\": \"2000-01-01\",
\"matched\": 1,
\"total\": 1,
\"authors\": \"Notmuch Test Suite\",
@@ -41,6 +42,7 @@ add_message "[subject]=\"json-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Ja
output=$(notmuch search --format=json "jsön-search-méssage" | notmuch_search_sanitize)
test_expect_equal "$output" "[{\"thread\": \"XXX\",
\"timestamp\": 946728000,
+\"date_relative\": \"2000-01-01\",
\"matched\": 1,
\"total\": 1,
\"authors\": \"Notmuch Test Suite\",
diff --git a/test/notmuch-test b/test/notmuch-test
index 113ea7cf..ded79e8f 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -48,6 +48,8 @@ TESTS="
search-folder-coherence
atomicity
python
+ hooks
+ argument-parsing
"
TESTS=${NOTMUCH_TESTS:=$TESTS}
@@ -62,10 +64,13 @@ else
TEST_TIMEOUT_CMD=""
fi
+trap 'e=$?; kill $!; exit $e' HUP INT TERM
# Run the tests
for test in $TESTS; do
- $TEST_TIMEOUT_CMD ./$test "$@"
+ $TEST_TIMEOUT_CMD ./$test "$@" &
+ wait $!
done
+trap - HUP INT TERM
# Report results
./aggregate-results.sh test-results/*
diff --git a/test/python b/test/python
index f737749f..c3aa7266 100755
--- a/test/python
+++ b/test/python
@@ -5,9 +5,7 @@ test_description="python bindings"
add_email_corpus
test_begin_subtest "compare thread ids"
-LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib \
-PYTHONPATH=$TEST_DIRECTORY/../bindings/python \
-python <<EOF | sort > OUTPUT
+test_python <<EOF
import notmuch
db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
q_new = notmuch.Query(db, 'tag:inbox')
@@ -15,5 +13,5 @@ for t in q_new.search_threads():
print t.get_thread_id()
EOF
notmuch search --output=threads tag:inbox | sed s/^thread:// | sort > EXPECTED
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file <(sort OUTPUT) EXPECTED
test_done
diff --git a/test/raw b/test/raw
index b7e265a8..99d3a3bf 100755
--- a/test/raw
+++ b/test/raw
@@ -1,4 +1,4 @@
-#!/usr//bin/env bash
+#!/usr/bin/env bash
test_description='notmuch show --format=raw'
. ./test-lib.sh
diff --git a/test/symbol-hiding b/test/symbol-hiding
index d0b31aec..68f0d1b1 100755
--- a/test/symbol-hiding
+++ b/test/symbol-hiding
@@ -12,15 +12,22 @@ test_description='exception symbol hiding'
. ./test-lib.sh
run_test(){
- result=$(LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib ./symbol-test 2>&1)
+ result=$(LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib $TEST_DIRECTORY/symbol-test 2>&1)
}
output="A Xapian exception occurred opening database: Couldn't stat 'fakedb/.notmuch/xapian'
caught No chert database found at path \`./nonexistant'"
-g++ -o symbol-test -I$TEST_DIRECTORY/../lib $TEST_DIRECTORY/symbol-test.cc -L$TEST_DIRECTORY/../lib -lnotmuch -lxapian
mkdir -p fakedb/.notmuch
+
test_expect_success 'running test' run_test
+
test_begin_subtest 'checking output'
test_expect_equal "$result" "$output"
+
+test_begin_subtest 'comparing existing to exported symbols'
+objdump -t $TEST_DIRECTORY/../lib/*.o | awk '$4 == ".text" && $6 ~ "^notmuch" {print $6}' | sort | uniq > ACTUAL
+sed -n 's/[[:blank:]]*\(notmuch_[^;]*\);/\1/p' $TEST_DIRECTORY/../notmuch.sym | sort | uniq > EXPORTED
+test_expect_equal_file EXPORTED ACTUAL
+
test_done
diff --git a/test/symbol-test.cc b/test/symbol-test.cc
index 1de06eae..1548ca40 100644
--- a/test/symbol-test.cc
+++ b/test/symbol-test.cc
@@ -1,17 +1,17 @@
#include <stdio.h>
#include <xapian.h>
#include <notmuch.h>
-main (int argc, char **argv){
- notmuch_database_t *notmuch
- = notmuch_database_open ("fakedb",
- NOTMUCH_DATABASE_MODE_READ_ONLY);
- try{
- (void)new Xapian::WritableDatabase ("./nonexistant", Xapian::DB_OPEN);
+int main() {
+ (void) notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY);
+
+ try {
+ (void) new Xapian::WritableDatabase("./nonexistant", Xapian::DB_OPEN);
} catch (const Xapian::Error &error) {
- printf("caught %s\n",error.get_msg().c_str());
+ printf("caught %s\n", error.get_msg().c_str());
return 0;
}
+
return 1;
}
diff --git a/test/test-lib.el b/test/test-lib.el
index 97ae5938..3b817c37 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -61,3 +61,18 @@ running, quit if it terminated."
(if (not (process-attributes pid))
(kill-emacs)
(run-at-time "1 min" nil 'orphan-watchdog pid)))
+
+(defun hook-counter (hook)
+ "Count how many times a hook is called. Increments
+`hook'-counter variable value if it is bound, otherwise does
+nothing."
+ (let ((counter (intern (concat (symbol-name hook) "-counter"))))
+ (if (boundp counter)
+ (set counter (1+ (symbol-value counter))))))
+
+(defun add-hook-counter (hook)
+ "Add hook to count how many times `hook' is called."
+ (add-hook hook (apply-partially 'hook-counter hook)))
+
+(add-hook-counter 'notmuch-hello-mode-hook)
+(add-hook-counter 'notmuch-hello-refresh-hook)
diff --git a/test/test-lib.sh b/test/test-lib.sh
index cf309f94..b5e346c0 100755..100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -116,6 +116,16 @@ do
esac
done
+if test -n "$debug"; then
+ print_subtest () {
+ printf " %-4s" "[$((test_count - 1))]"
+ }
+else
+ print_subtest () {
+ true
+ }
+fi
+
if test -n "$color"; then
say_color () {
(
@@ -132,6 +142,7 @@ if test -n "$color"; then
printf " "
printf "$@"
tput sgr0
+ print_subtest
)
}
else
@@ -140,6 +151,7 @@ else
shift
printf " "
printf "$@"
+ print_subtest
}
fi
@@ -398,6 +410,8 @@ emacs_deliver_message ()
(insert \"${body}\")
$@
(message-send-and-exit))"
+ # opportunistically quit smtp-dummy in case above fails.
+ { echo QUIT > /dev/tcp/localhost/25025; } 2>/dev/null
wait ${smtp_dummy_pid}
notmuch new >/dev/null
}
@@ -427,7 +441,7 @@ test_begin_subtest ()
error "bug in test script: Missing test_expect_equal in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
fi
test_subtest_name="$1"
- test_subtest_known_broken_=
+ test_reset_state_
# Remember stdout and stderr file descriptors and redirect test
# output to the previously prepared file descriptors 3 and 4 (see
# below)
@@ -546,6 +560,33 @@ test_have_prereq () {
esac
}
+# declare prerequisite for the given external binary
+test_declare_external_prereq () {
+ binary="$1"
+ test "$#" = 2 && name=$2 || name="$binary(1)"
+
+ hash $binary 2>/dev/null || eval "
+ test_missing_external_prereq_${binary}_=t
+$binary () {
+ echo -n \"\$test_subtest_missing_external_prereqs_ \" | grep -qe \" $name \" ||
+ test_subtest_missing_external_prereqs_=\"\$test_subtest_missing_external_prereqs_ $name\"
+ false
+}"
+}
+
+# Explicitly require external prerequisite. Useful when binary is
+# called indirectly (e.g. from emacs).
+# Returns success if dependency is available, failure otherwise.
+test_require_external_prereq () {
+ binary="$1"
+ if [ "$(eval echo -n \$test_missing_external_prereq_${binary}_)" = t ]; then
+ # dependency is missing, call the replacement function to note it
+ eval "$binary"
+ else
+ true
+ fi
+}
+
# You are not expected to call test_ok_ and test_failure_ directly, use
# the text_expect_* functions instead.
@@ -579,14 +620,14 @@ test_failure_message_ () {
}
test_known_broken_ok_ () {
- test_subtest_known_broken_=
+ test_reset_state_
test_fixed=$(($test_fixed+1))
say_color pass "%-6s" "FIXED"
echo " $@"
}
test_known_broken_failure_ () {
- test_subtest_known_broken_=
+ test_reset_state_
test_broken=$(($test_broken+1))
test_failure_message_ "BROKEN" "$@"
return 1
@@ -622,18 +663,32 @@ test_skip () {
fi
case "$to_skip" in
t)
- test_subtest_known_broken_=
- say_color skip >&3 "skipping test: $@"
- say_color skip "%-6s" "SKIP"
- echo " $1"
- : true
+ test_report_skip_ "$@"
;;
*)
- false
+ test_check_missing_external_prereqs_ "$@"
;;
esac
}
+test_check_missing_external_prereqs_ () {
+ if test -n "$test_subtest_missing_external_prereqs_"; then
+ say_color skip >&3 "missing prerequisites:"
+ echo "$test_subtest_missing_external_prereqs_" >&3
+ test_report_skip_ "$@"
+ else
+ false
+ fi
+}
+
+test_report_skip_ () {
+ test_reset_state_
+ say_color skip >&3 "skipping test:"
+ echo " $@" >&3
+ say_color skip "%-6s" "SKIP"
+ echo " $1"
+}
+
test_subtest_known_broken () {
test_subtest_known_broken_=t
}
@@ -642,10 +697,14 @@ test_expect_success () {
test "$#" = 3 && { prereq=$1; shift; } || prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
+ test_reset_state_
if ! test_skip "$@"
then
test_run_ "$2"
- if [ "$?" = 0 -a "$eval_ret" = 0 ]
+ run_ret="$?"
+ # test_run_ may update missing external prerequisites
+ test_check_missing_external_prereqs_ "$@" ||
+ if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
then
test_ok_ "$1"
else
@@ -658,10 +717,14 @@ test_expect_code () {
test "$#" = 4 && { prereq=$1; shift; } || prereq=
test "$#" = 3 ||
error "bug in the test script: not 3 or 4 parameters to test-expect-code"
+ test_reset_state_
if ! test_skip "$@"
then
test_run_ "$3"
- if [ "$?" = 0 -a "$eval_ret" = "$1" ]
+ run_ret="$?"
+ # test_run_ may update missing external prerequisites,
+ test_check_missing_external_prereqs_ "$@" ||
+ if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
then
test_ok_ "$2"
else
@@ -684,6 +747,7 @@ test_external () {
error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
descr="$1"
shift
+ test_reset_state_
if ! test_skip "$descr" "$@"
then
# Announce the script to reduce confusion about the
@@ -842,17 +906,22 @@ EOF
}
test_emacs () {
+ # test dependencies beforehand to avoid the waiting loop below
+ test_require_external_prereq emacs || return
+ test_require_external_prereq emacsclient || return
+
if [ -z "$EMACS_SERVER" ]; then
- EMACS_SERVER="notmuch-test-suite-$$"
+ server_name="notmuch-test-suite-$$"
# start a detached session with an emacs server
# user's TERM is given to dtach which assumes a minimally
# VT100-compatible terminal -- and emacs inherits that
TERM=$ORIGINAL_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
--no-window-system \
- --eval '(setq server-name \"$EMACS_SERVER\")' \
+ --eval '(setq server-name \"$server_name\")' \
--eval '(server-start)' \
--eval '(orphan-watchdog $$)'" || return
+ EMACS_SERVER="$server_name"
# wait until the emacs server is up
until test_emacs '()' 2>/dev/null; do
sleep 1
@@ -862,6 +931,67 @@ test_emacs () {
emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
}
+test_python() {
+ export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib
+ export PYTHONPATH=$TEST_DIRECTORY/../bindings/python
+
+ # Some distros (e.g. Arch Linux) ship Python 2.* as /usr/bin/python2,
+ # most others as /usr/bin/python. So first try python2, and fallback to
+ # python if python2 doesn't exist.
+ cmd=python2
+ [[ "$test_missing_external_prereq_python2_" = t ]] && cmd=python
+
+ (echo "import sys; _orig_stdout=sys.stdout; sys.stdout=open('OUTPUT', 'w')"; cat) \
+ | $cmd -
+}
+
+# Creates a script that counts how much time it is executed and calls
+# notmuch. $notmuch_counter_command is set to the path to the
+# generated script. Use notmuch_counter_value() function to get the
+# current counter value.
+notmuch_counter_reset () {
+ notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
+ if [ ! -x "$notmuch_counter_command" ]; then
+ notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
+ cat >"$notmuch_counter_command" <<EOF || return
+#!/bin/sh
+
+read count < "$notmuch_counter_state_path"
+echo \$((count + 1)) > "$notmuch_counter_state_path"
+
+exec notmuch "\$@"
+EOF
+ chmod +x "$notmuch_counter_command" || return
+ fi
+
+ echo 0 > "$notmuch_counter_state_path"
+}
+
+# Returns the current notmuch counter value.
+notmuch_counter_value () {
+ if [ -r "$notmuch_counter_state_path" ]; then
+ read count < "$notmuch_counter_state_path"
+ else
+ count=0
+ fi
+ echo $count
+}
+
+test_reset_state_ () {
+ test -z "$test_init_done_" && test_init_
+
+ test_subtest_known_broken_=
+ test_subtest_missing_external_prereqs_=
+}
+
+# called once before the first subtest
+test_init_ () {
+ test_init_done_=t
+
+ # skip all tests if there were external prerequisites missing during init
+ test_check_missing_external_prereqs_ "all tests in $this_test" && test_done
+}
+
find_notmuch_path ()
{
@@ -1069,3 +1199,12 @@ test -z "$NO_PYTHON" && test_set_prereq PYTHON
# test whether the filesystem supports symbolic links
ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
rm -f y
+
+# declare prerequisites for external binaries used in tests
+test_declare_external_prereq dtach
+test_declare_external_prereq emacs
+test_declare_external_prereq emacsclient
+test_declare_external_prereq gdb
+test_declare_external_prereq gpg
+test_declare_external_prereq python
+test_declare_external_prereq python2