]> git.notmuchmail.org Git - notmuch/commitdiff
Merge branch 'release'
authorDavid Bremner <david@tethera.net>
Sun, 19 Mar 2017 00:02:42 +0000 (21:02 -0300)
committerDavid Bremner <david@tethera.net>
Sun, 19 Mar 2017 00:02:42 +0000 (21:02 -0300)
Merge in memory fixes

43 files changed:
Makefile
bindings/Makefile.local
bindings/python/notmuch/database.py
bindings/ruby/extconf.rb
configure
emacs/notmuch-crypto.el
lib/database.cc
lib/message.cc
mime-node.c
notmuch-client.h
notmuch-new.c
notmuch-reply.c
notmuch-show.c
performance-test/M02-show.sh [new file with mode: 0755]
performance-test/M03-search.sh [new file with mode: 0755]
performance-test/perf-test-lib.sh
test/Makefile.local
test/README
test/T000-basic.sh
test/T010-help-test.sh
test/T020-compact.sh
test/T050-new.sh
test/T070-insert.sh
test/T150-tagging.sh
test/T160-json.sh
test/T190-multipart.sh
test/T240-dump-restore.sh
test/T310-emacs.sh
test/T340-maildir-sync.sh
test/T350-crypto.sh
test/T355-smime.sh
test/T380-atomicity.sh
test/T390-python.sh
test/T400-hooks.sh
test/T530-upgrade.sh
test/T560-lib-error.sh
test/T570-revision-tracking.sh
test/T600-named-queries.sh
test/T660-bad-date.sh [new file with mode: 0755]
test/atomicity.py
test/test-databases/Makefile.local
test/test-lib.sh
test/test-verbose

index 0ef57fa9fabed81019822e033b29802bb0bbb151..d2010fe48669e549cc4c0865362c3f5103a349ca 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,35 @@ include Makefile.config
 global_deps = Makefile Makefile.config Makefile.local \
        $(subdirs:%=%/Makefile) $(subdirs:%=%/Makefile.local)
 
+INCLUDE_MORE := yes
+ifneq ($(filter clean distclean dataclean, $(word 1, $(MAKECMDGOALS))),)
+CLEAN_GOAL := $(word 1, $(MAKECMDGOALS))
+
+# If there are more goals following CLEAN_GOAL, run $(MAKE)s in parts.
+ifneq ($(word 2, $(MAKECMDGOALS)),)
+INCLUDE_MORE := no
+FOLLOWING_GOALS := $(wordlist 2, 99, $(MAKECMDGOALS))
+
+.PHONY: $(FOLLOWING_GOALS) make_in_parts
+$(FOLLOWING_GOALS):
+       @true
+$(CLEAN_GOAL): make_in_parts
+make_in_parts:
+       $(MAKE) $(CLEAN_GOAL)
+       $(MAKE) $(FOLLOWING_GOALS) configure_options="$(configure_options)"
+endif
+
+else
+CLEAN_GOAL :=
+endif
+
+# Potentially speedup make clean, distclean and dataclean ; avoid
+# re-creating Makefile.config if it exists but configure is newer.
+ifneq ($(CLEAN_GOAL),)
+Makefile.config: | $(srcdir)/configure
+else
 Makefile.config: $(srcdir)/configure
+endif
 ifeq ($(configure_options),)
        @echo ""
        @echo "Note: Calling ./configure with no command-line arguments. This is often fine,"
@@ -33,9 +61,11 @@ ifeq ($(configure_options),)
 endif
        $(srcdir)/configure $(configure_options)
 
+ifeq ($(INCLUDE_MORE),yes)
 # runtime variable definitions available in all subdirs
 include $(srcdir)/Makefile.global
 # Finally, include all of the Makefile.local fragments where all the
 # real work is done.
 
 include $(subdirs:%=%/Makefile.local) Makefile.local
+endif
index 11d11d4bcbeb19d217f221f8d250be0d4e2cde32..17b561caac52dfc17a1f4fc9e56758b32dbb25fd 100644 (file)
@@ -8,6 +8,7 @@ ifeq ($(HAVE_RUBY_DEV),1)
        cd $(dir)/ruby && \
                EXTRA_LDFLAGS="$(NO_UNDEFINED_LDFLAGS)" \
                LIBNOTMUCH="../../lib/$(LINKER_NAME)" \
+               NOTMUCH_SRCDIR='$(NOTMUCH_SRCDIR)' \
                ruby extconf.rb --vendor
        $(MAKE) -C $(dir)/ruby
 endif
index 67fb1c41142428ed6c06e36a985de8f1f784a1db..8f918069f34d24ad5059a3a89e0a5e55cd8a8b95 100644 (file)
@@ -86,6 +86,11 @@ class Database(object):
     _get_version.argtypes = [NotmuchDatabaseP]
     _get_version.restype = c_uint
 
+    """notmuch_database_get_revision"""
+    _get_revision = nmlib.notmuch_database_get_revision
+    _get_revision.argtypes = [NotmuchDatabaseP, POINTER(c_char_p)]
+    _get_revision.restype = c_uint
+
     """notmuch_database_open"""
     _open = nmlib.notmuch_database_open
     _open.argtypes = [c_char_p, c_uint, POINTER(NotmuchDatabaseP)]
@@ -261,6 +266,17 @@ class Database(object):
         self._assert_db_is_initialized()
         return Database._get_version(self._db)
 
+    def get_revision (self):
+        """Returns the committed database revison and UUID
+
+        :returns: (revison, uuid) The database revision as a positive integer
+        and the UUID of the database.
+        """
+        self._assert_db_is_initialized()
+        uuid = c_char_p ()
+        revision = Database._get_revision(self._db, byref (uuid))
+        return (revision, uuid.value.decode ('utf-8'))
+
     _needs_upgrade = nmlib.notmuch_database_needs_upgrade
     _needs_upgrade.argtypes = [NotmuchDatabaseP]
     _needs_upgrade.restype = bool
index ddaa6841e5ff2d507c65501f6d81dd00f9e942fe..161de5a2c7c52bb6d5130ee6db3616c36acdba1d 100644 (file)
@@ -5,7 +5,7 @@
 
 require 'mkmf'
 
-dir = File.join('..', '..', 'lib')
+dir = File.join(ENV['NOTMUCH_SRCDIR'], 'lib')
 
 # includes
 $INCFLAGS = "-I#{dir} #{$INCFLAGS}"
index fa77eb8fd4b7b406f2b3a097137c4c5001c285f9..6c782e16d5a63a746e3b49691bcc398fcb7f63cd 100755 (executable)
--- a/configure
+++ b/configure
@@ -19,7 +19,12 @@ To work around this problem you may try to execute:
 # Store original IFS value so it can be changed (and restored) in many places.
 readonly DEFAULT_IFS="$IFS"
 
+# The top-level directory for the source. This ./configure and all Makefiles
+# are good with ${srcdir} usually being relative. Some components (e.g. tests)
+# are executed in subdirectories and for those it is simpler to use
+# ${NOTMUCH_SRCDIR} which holds absolute path to the source.
 srcdir=$(dirname "$0")
+NOTMUCH_SRCDIR=$(cd "$srcdir" && pwd)
 
 subdirs="util compat lib parse-time-string completion doc emacs"
 subdirs="${subdirs} performance-test test test/test-databases"
@@ -42,6 +47,12 @@ if [ "$srcdir" != "." ]; then
     # Emacs only likes to generate compiled files next to the .el files
     # by default so copy these as well (which is not ideal).
     cp -a "$srcdir"/emacs/*.el emacs
+
+    # We were not able to create fully working Makefile using ruby mkmf.rb
+    # so ruby bindings source files are copied as well (ditto -- not ideal).
+    mkdir bindings/ruby
+    cp -a "$srcdir"/bindings/ruby/*.[ch] bindings/ruby
+    cp -a "$srcdir"/bindings/ruby/extconf.rb bindings/ruby
 fi
 
 # Set several defaults (optionally specified by the user in
@@ -352,8 +363,8 @@ int main(void) {
     return 0;
 }
 EOF
-if ${CC} ${CFLAGS} _libversion.c -o _libversion > /dev/null 2>&1 && \
-       ./_libversion > _libversion.sh && . ./_libversion.sh
+if ${CC} ${CFLAGS} -I"$srcdir" _libversion.c -o _libversion > /dev/null 2>&1 \
+       && ./_libversion > _libversion.sh && . ./_libversion.sh
 then
     printf "OK.\n"
 else
@@ -493,8 +504,7 @@ else
 fi
 
 if ! pkg-config --exists zlib; then
-  ${CC} ${zlib_cflags} -o compat/gen_zlib_pc \
-         "$srcdir"/compat/gen_zlib_pc.c ${zlib_ldflags} > /dev/null 2>&1 &&
+  ${CC} -o compat/gen_zlib_pc "$srcdir"/compat/gen_zlib_pc.c >/dev/null 2>&1 &&
   compat/gen_zlib_pc > compat/zlib.pc &&
   PKG_CONFIG_PATH="$PKG_CONFIG_PATH":compat &&
   export PKG_CONFIG_PATH
@@ -914,6 +924,7 @@ cat > Makefile.config <<EOF
 # the configure script). This may be different than the build
 # directory (the current directory at the time configure was run).
 srcdir = ${srcdir}
+NOTMUCH_SRCDIR = ${NOTMUCH_SRCDIR}
 
 # subdirectories to build
 subdirs = ${subdirs}
@@ -1165,6 +1176,8 @@ cat > sh.config <<EOF
 # This sh.config was automatically generated by the ./configure
 # script of notmuch.
 
+NOTMUCH_SRCDIR='${NOTMUCH_SRCDIR}'
+
 # Whether the Xapian version in use supports compaction
 NOTMUCH_HAVE_XAPIAN_COMPACT=${have_xapian_compact}
 
index 68a7e9f3735a814ce70b55948c3cf6ade687aea9..0af727ef4dc68258b039691e0e85d58e95f48a72 100644 (file)
@@ -21,6 +21,7 @@
 
 ;;; Code:
 
+(require 'epg)
 (require 'notmuch-lib)
 
 (defcustom notmuch-crypto-process-mime nil
@@ -140,7 +141,7 @@ mode."
     (with-selected-window window
       (with-current-buffer buffer
        (goto-char (point-max))
-       (call-process "gpg" nil t t "--list-keys" fingerprint))
+       (call-process epg-gpg-program nil t t "--list-keys" fingerprint))
       (recenter -1))))
 
 (defun notmuch-crypto-sigstatus-error-callback (button)
@@ -151,9 +152,9 @@ mode."
     (with-selected-window window
       (with-current-buffer buffer
        (goto-char (point-max))
-       (call-process "gpg" nil t t "--recv-keys" keyid)
+       (call-process epg-gpg-program nil t t "--recv-keys" keyid)
        (insert "\n")
-       (call-process "gpg" nil t t "--list-keys" keyid))
+       (call-process epg-gpg-program nil t t "--list-keys" keyid))
       (recenter -1))
     (notmuch-show-refresh-view)))
 
index b7fc53ee18734d801201f73d841765cae8a89578..a679cbabbac95a2d39885292341370e1d040d8c0 100644 (file)
@@ -2493,53 +2493,53 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
     if (ret)
        goto DONE;
 
-    try {
-       /* Before we do any real work, (especially before doing a
-        * potential SHA-1 computation on the entire file's contents),
-        * let's make sure that what we're looking at looks like an
-        * actual email message.
-        */
-       from = _notmuch_message_file_get_header (message_file, "from");
-       subject = _notmuch_message_file_get_header (message_file, "subject");
-       to = _notmuch_message_file_get_header (message_file, "to");
+    /* Before we do any real work, (especially before doing a
+     * potential SHA-1 computation on the entire file's contents),
+     * let's make sure that what we're looking at looks like an
+     * actual email message.
+     */
+    from = _notmuch_message_file_get_header (message_file, "from");
+    subject = _notmuch_message_file_get_header (message_file, "subject");
+    to = _notmuch_message_file_get_header (message_file, "to");
+
+    if ((from == NULL || *from == '\0') &&
+       (subject == NULL || *subject == '\0') &&
+       (to == NULL || *to == '\0')) {
+       ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
+       goto DONE;
+    }
 
-       if ((from == NULL || *from == '\0') &&
-           (subject == NULL || *subject == '\0') &&
-           (to == NULL || *to == '\0'))
-       {
-           ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
-           goto DONE;
-       }
+    /* Now that we're sure it's mail, the first order of business
+     * is to find a message ID (or else create one ourselves).
+     */
+    header = _notmuch_message_file_get_header (message_file, "message-id");
+    if (header && *header != '\0') {
+       message_id = _parse_message_id (message_file, header, NULL);
 
-       /* Now that we're sure it's mail, the first order of business
-        * is to find a message ID (or else create one ourselves). */
+       /* So the header value isn't RFC-compliant, but it's
+        * better than no message-id at all.
+        */
+       if (message_id == NULL)
+           message_id = talloc_strdup (message_file, header);
+    }
 
-       header = _notmuch_message_file_get_header (message_file, "message-id");
-       if (header && *header != '\0') {
-           message_id = _parse_message_id (message_file, header, NULL);
+    if (message_id == NULL ) {
+       /* No message-id at all, let's generate one by taking a
+        * hash over the file's contents.
+        */
+       char *sha1 = _notmuch_sha1_of_file (filename);
 
-           /* So the header value isn't RFC-compliant, but it's
-            * better than no message-id at all. */
-           if (message_id == NULL)
-               message_id = talloc_strdup (message_file, header);
+       /* If that failed too, something is really wrong. Give up. */
+       if (sha1 == NULL) {
+           ret = NOTMUCH_STATUS_FILE_ERROR;
+           goto DONE;
        }
 
-       if (message_id == NULL ) {
-           /* No message-id at all, let's generate one by taking a
-            * hash over the file's contents. */
-           char *sha1 = _notmuch_sha1_of_file (filename);
-
-           /* If that failed too, something is really wrong. Give up. */
-           if (sha1 == NULL) {
-               ret = NOTMUCH_STATUS_FILE_ERROR;
-               goto DONE;
-           }
-
-           message_id = talloc_asprintf (message_file,
-                                         "notmuch-sha1-%s", sha1);
-           free (sha1);
-       }
+       message_id = talloc_asprintf (message_file, "notmuch-sha1-%s", sha1);
+       free (sha1);
+    }
 
+    try {
        /* Now that we have a message ID, we get a message object,
         * (which may or may not reference an existing document in the
         * database). */
index 36a07a8890b0dd52a092fc8c88434676cc4193be..cb313326270e6bc3b0ba5813a5491269e5a62ebb 100644 (file)
@@ -1034,10 +1034,16 @@ _notmuch_message_set_header_values (notmuch_message_t *message,
 
     /* GMime really doesn't want to see a NULL date, so protect its
      * sensibilities. */
-    if (date == NULL || *date == '\0')
+    if (date == NULL || *date == '\0') {
        time_value = 0;
-    else
+    } else {
        time_value = g_mime_utils_header_decode_date (date, NULL);
+       /*
+        * Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=779923
+        */
+       if (time_value < 0)
+           time_value = 0;
+    }
 
     message->doc.add_value (NOTMUCH_VALUE_TIMESTAMP,
                            Xapian::sortable_serialise (time_value));
index c9b82330f6e08908e85fcae2891bb003c5dfec98..f719422ec678bbe340cd670861bb5cf0b0ca347e 100644 (file)
@@ -322,20 +322,21 @@ mime_node_child (mime_node_t *parent, int child)
 static mime_node_t *
 _mime_node_seek_dfs_walk (mime_node_t *node, int *n)
 {
-    mime_node_t *ret = NULL;
     int i;
 
     if (*n == 0)
        return node;
 
     *n -= 1;
-    for (i = 0; i < node->nchildren && !ret; i++) {
+    for (i = 0; i < node->nchildren; i++) {
        mime_node_t *child = mime_node_child (node, i);
-       ret = _mime_node_seek_dfs_walk (child, n);
-       if (!ret)
-           talloc_free (child);
+       mime_node_t *ret = _mime_node_seek_dfs_walk (child, n);
+       if (ret)
+           return ret;
+
+       talloc_free (child);
     }
-    return ret;
+    return NULL;
 }
 
 mime_node_t *
index 1099122426afc9267a14219d26da2cbde0615c31..7a674873d5985b122a6ee99cf1f2861e6faac4a2 100644 (file)
@@ -83,7 +83,6 @@ typedef struct notmuch_show_params {
     notmuch_bool_t entire_thread;
     notmuch_bool_t omit_excluded;
     notmuch_bool_t output_body;
-    notmuch_bool_t raw;
     int part;
     notmuch_crypto_t crypto;
     notmuch_bool_t include_html;
index 13212639cc8ec669df4ea3d47f6c0d4d9a3fd834..e2822e23060786ee9674e3d9371cec44782315ba 100644 (file)
@@ -905,10 +905,9 @@ print_results (const add_files_state_t *state)
                state->processed_files == 1 ? "file" : "total files");
        notmuch_time_print_formatted_seconds (elapsed);
        if (elapsed > 1)
-           printf (" (%d files/sec.).\033[K\n",
+           printf (" (%d files/sec.)",
                    (int) (state->processed_files / elapsed));
-       else
-           printf (".\033[K\n");
+       printf (".%s\n", (state->output_is_a_tty) ? "\033[K" : "");
     }
 
     if (state->added_messages)
index 8c894974485d4f4ae32997388425904640d941da..166a59467eec711ac8fb9b5d22f3e6b6027818da 100644 (file)
@@ -701,11 +701,6 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
     int opt_index;
     notmuch_show_params_t params = {
        .part = -1,
-       .crypto = {
-           .verify = FALSE,
-           .decrypt = FALSE,
-           .gpgpath = NULL
-       }
     };
     int format = FORMAT_DEFAULT;
     int reply_all = TRUE;
index 1954096d9091d43c9cd5cf34a3d856aa635ed3d4..7451d5ab563cd03a33df05671d4efce5af7eb12c 100644 (file)
 #include "gmime-filter-reply.h"
 #include "sprinter.h"
 
-static notmuch_status_t
-format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
-                 int indent, const notmuch_show_params_t *params);
-
-static const notmuch_show_format_t format_text = {
-    .new_sprinter = sprinter_text_create,
-    .part = format_part_text,
-};
-
-static notmuch_status_t
-format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,
-                           int indent, const notmuch_show_params_t *params);
-
-static const notmuch_show_format_t format_json = {
-    .new_sprinter = sprinter_json_create,
-    .part = format_part_sprinter_entry,
-};
-
-static const notmuch_show_format_t format_sexp = {
-    .new_sprinter = sprinter_sexp_create,
-    .part = format_part_sprinter_entry,
-};
-
-static notmuch_status_t
-format_part_mbox (const void *ctx, sprinter_t *sp, mime_node_t *node,
-                 int indent, const notmuch_show_params_t *params);
-
-static const notmuch_show_format_t format_mbox = {
-    .new_sprinter = sprinter_text_create,
-    .part = format_part_mbox,
-};
-
-static notmuch_status_t
-format_part_raw (unused (const void *ctx), sprinter_t *sp, mime_node_t *node,
-                unused (int indent),
-                unused (const notmuch_show_params_t *params));
-
-static const notmuch_show_format_t format_raw = {
-    .new_sprinter = sprinter_text_create,
-    .part = format_part_raw,
-};
-
 static const char *
 _get_tags_as_string (const void *ctx, notmuch_message_t *message)
 {
@@ -1029,10 +987,43 @@ enum {
     NOTMUCH_FORMAT_RAW
 };
 
+static const notmuch_show_format_t format_json = {
+    .new_sprinter = sprinter_json_create,
+    .part = format_part_sprinter_entry,
+};
+
+static const notmuch_show_format_t format_sexp = {
+    .new_sprinter = sprinter_sexp_create,
+    .part = format_part_sprinter_entry,
+};
+
+static const notmuch_show_format_t format_text = {
+    .new_sprinter = sprinter_text_create,
+    .part = format_part_text,
+};
+
+static const notmuch_show_format_t format_mbox = {
+    .new_sprinter = sprinter_text_create,
+    .part = format_part_mbox,
+};
+
+static const notmuch_show_format_t format_raw = {
+    .new_sprinter = sprinter_text_create,
+    .part = format_part_raw,
+};
+
+static const notmuch_show_format_t *formatters[] = {
+    [NOTMUCH_FORMAT_JSON] = &format_json,
+    [NOTMUCH_FORMAT_SEXP] = &format_sexp,
+    [NOTMUCH_FORMAT_TEXT] = &format_text,
+    [NOTMUCH_FORMAT_MBOX] = &format_mbox,
+    [NOTMUCH_FORMAT_RAW] = &format_raw,
+};
+
 enum {
-    ENTIRE_THREAD_DEFAULT,
-    ENTIRE_THREAD_TRUE,
-    ENTIRE_THREAD_FALSE,
+    ENTIRE_THREAD_DEFAULT = -1,
+    ENTIRE_THREAD_FALSE = FALSE,
+    ENTIRE_THREAD_TRUE = TRUE,
 };
 
 /* The following is to allow future options to be added more easily */
@@ -1048,25 +1039,20 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     notmuch_query_t *query;
     char *query_string;
     int opt_index, ret;
-    const notmuch_show_format_t *format = &format_text;
+    const notmuch_show_format_t *formatter;
     sprinter_t *sprinter;
     notmuch_show_params_t params = {
        .part = -1,
        .omit_excluded = TRUE,
        .output_body = TRUE,
-       .crypto = {
-           .verify = FALSE,
-           .decrypt = FALSE,
-           .gpgpath = NULL
-       },
-       .include_html = FALSE
     };
-    int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
+    int format = NOTMUCH_FORMAT_NOT_SPECIFIED;
     int exclude = EXCLUDE_TRUE;
     int entire_thread = ENTIRE_THREAD_DEFAULT;
+    notmuch_bool_t single_message;
 
     notmuch_opt_desc_t options[] = {
-       { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
+       { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
          (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
                                  { "text", NOTMUCH_FORMAT_TEXT },
                                  { "sexp", NOTMUCH_FORMAT_SEXP },
@@ -1102,40 +1088,25 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     if (params.crypto.decrypt)
        params.crypto.verify = TRUE;
 
-    if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
+    /* specifying a part implies single message display */
+    single_message = params.part >= 0;
+
+    if (format == NOTMUCH_FORMAT_NOT_SPECIFIED) {
        /* if part was requested and format was not specified, use format=raw */
        if (params.part >= 0)
-           format_sel = NOTMUCH_FORMAT_RAW;
+           format = NOTMUCH_FORMAT_RAW;
        else
-           format_sel = NOTMUCH_FORMAT_TEXT;
+           format = NOTMUCH_FORMAT_TEXT;
     }
 
-    switch (format_sel) {
-    case NOTMUCH_FORMAT_JSON:
-       format = &format_json;
-       break;
-    case NOTMUCH_FORMAT_TEXT:
-       format = &format_text;
-       break;
-    case NOTMUCH_FORMAT_SEXP:
-       format = &format_sexp;
-       break;
-    case NOTMUCH_FORMAT_MBOX:
+    if (format == NOTMUCH_FORMAT_MBOX) {
        if (params.part > 0) {
            fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");
            return EXIT_FAILURE;
        }
-
-       format = &format_mbox;
-       break;
-    case NOTMUCH_FORMAT_RAW:
-       format = &format_raw;
-       /* If --format=raw specified without specifying part, we can only
-        * output single message, so set part=0 */
-       if (params.part < 0)
-           params.part = 0;
-       params.raw = TRUE;
-       break;
+    } else if (format == NOTMUCH_FORMAT_RAW) {
+       /* raw format only supports single message display */
+       single_message = TRUE;
     }
 
     notmuch_exit_if_unsupported_format ();
@@ -1143,10 +1114,12 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     /* Default is entire-thread = FALSE except for format=json and
      * format=sexp. */
     if (entire_thread == ENTIRE_THREAD_DEFAULT) {
-       if (format == &format_json || format == &format_sexp)
-           entire_thread = ENTIRE_THREAD_TRUE;
+       if (format == NOTMUCH_FORMAT_JSON || format == NOTMUCH_FORMAT_SEXP)
+           params.entire_thread = TRUE;
        else
-           entire_thread = ENTIRE_THREAD_FALSE;
+           params.entire_thread = FALSE;
+    } else {
+       params.entire_thread = entire_thread;
     }
 
     if (!params.output_body) {
@@ -1154,22 +1127,17 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
            fprintf (stderr, "Warning: --body=false is incompatible with --part > 0. Disabling.\n");
            params.output_body = TRUE;
        } else {
-           if (format != &format_json && format != &format_sexp)
+           if (format != NOTMUCH_FORMAT_JSON && format != NOTMUCH_FORMAT_SEXP)
                fprintf (stderr,
                         "Warning: --body=false only implemented for format=json and format=sexp\n");
        }
     }
 
     if (params.include_html &&
-        (format_sel != NOTMUCH_FORMAT_JSON && format_sel != NOTMUCH_FORMAT_SEXP)) {
+        (format != NOTMUCH_FORMAT_JSON && format != NOTMUCH_FORMAT_SEXP)) {
        fprintf (stderr, "Warning: --include-html only implemented for format=json and format=sexp\n");
     }
 
-    if (entire_thread == ENTIRE_THREAD_TRUE)
-       params.entire_thread = TRUE;
-    else
-       params.entire_thread = FALSE;
-
     query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);
     if (query_string == NULL) {
        fprintf (stderr, "Out of memory\n");
@@ -1196,12 +1164,13 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     }
 
     /* Create structure printer. */
-    sprinter = format->new_sprinter(config, stdout);
+    formatter = formatters[format];
+    sprinter = formatter->new_sprinter(config, stdout);
 
     /* If a single message is requested we do not use search_excludes. */
-    if (params.part >= 0)
-       ret = do_show_single (config, query, format, sprinter, &params);
-    else {
+    if (single_message) {
+       ret = do_show_single (config, query, formatter, sprinter, &params);
+    else {
        /* We always apply set the exclude flag. The
         * exclude=true|false option controls whether or not we return
         * threads that only match in an excluded message */
@@ -1219,7 +1188,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
            params.omit_excluded = FALSE;
        }
 
-       ret = do_show (config, query, format, sprinter, &params);
+       ret = do_show (config, query, formatter, sprinter, &params);
     }
 
     notmuch_crypto_cleanup (&params.crypto);
diff --git a/performance-test/M02-show.sh b/performance-test/M02-show.sh
new file mode 100755 (executable)
index 0000000..d73035e
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+test_description='show'
+
+. ./perf-test-lib.sh || exit 1
+
+memory_start
+
+memory_run 'show *' "notmuch show '*' 1>/dev/null"
+memory_run 'show --format=json *' "notmuch show --format=json '*' 1>/dev/null"
+memory_run 'show --format=sexp *' "notmuch show --format=sexp '*' 1>/dev/null"
+
+memory_done
diff --git a/performance-test/M03-search.sh b/performance-test/M03-search.sh
new file mode 100755 (executable)
index 0000000..8d026ee
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+test_description='search'
+
+. ./perf-test-lib.sh || exit 1
+
+memory_start
+
+memory_run 'search *' "notmuch search '*' 1>/dev/null"
+memory_run 'search --format=json *' "notmuch search --format=json '*' 1>/dev/null"
+memory_run 'search --format=sexp *' "notmuch search --format=sexp '*' 1>/dev/null"
+
+memory_done
index 00d2f1c6050bb7330bba19e4a17a7bbe097cae42..c89d5aab39a069e7ee28596b3f20ea0e7a8803ed 100644 (file)
@@ -149,7 +149,7 @@ memory_run ()
 
     printf "[ %d ]\t%s\n" $test_count "$1"
 
-    NOTMUCH_TALLOC_REPORT="$talloc_log" valgrind --leak-check=full --log-file="$log_file" $2
+    NOTMUCH_TALLOC_REPORT="$talloc_log" eval "valgrind --leak-check=full --log-file='$log_file' $2"
 
     awk '/LEAK SUMMARY/,/suppressed/ { sub(/^==[0-9]*==/," "); print }' "$log_file"
     echo
index f8cf90d07e2dc5c1acd59ad13531800a783eb7a5..4680597292cf5bdb7bb8f593769842e8f12f66b7 100644 (file)
@@ -61,7 +61,7 @@ test-binaries: $(TEST_BINARIES)
 
 test:  all test-binaries
 ifeq ($V,)
-       @echo 'Use "$(MAKE) V=1" to print test headings and PASSing results.'
+       @echo 'Use "$(MAKE) V=1" to see the details for passing and known broken tests.'
        @env NOTMUCH_TEST_QUIET=1 ${test_src_dir}/notmuch-test $(OPTIONS)
 else
 # The user has explicitly enabled quiet execution.
index 104a120ea28bfb7250243f1d331ed8efd1e99fa0..dcd05237a0623c859af0ae67e033994137dd0d54 100644 (file)
@@ -189,16 +189,21 @@ Test harness library
 There are a handful helper functions defined in the test harness
 library for your script to use.
 
- test_expect_success <message> <script>
+ test_begin_subtest <message>
+
+   Set the test description message for a subsequent test_expect_*
+   invocation (see below).
 
-   This takes two strings as parameter, and evaluates the
+ test_expect_success <script>
+
+   This takes a string as parameter, and evaluates the
    <script>.  If it yields success, test is considered
-   successful.  <message> should state what it is testing.
+   successful.
 
- test_begin_subtest <message>
+ test_expect_code <code> <script>
 
-   Set the test description message for a subsequent test_expect_equal
-   invocation (see below).
+   This takes two strings as parameter, and evaluates the <script>.
+   If it yields <code> exit status, test is considered successful.
 
  test_subtest_known_broken
 
index 0a8d6cdf40fc3ecc83d05f5347cd73c67e62f5f8..36a7ca4c5bdfb78ed28430ab6c471123780b85f9 100755 (executable)
@@ -18,26 +18,21 @@ fi
 
 ################################################################
 # Test harness
-test_expect_success 'success is reported like this' '
-    :
-'
+test_begin_subtest 'success is reported like this'
+test_expect_success ':'
+
+test_begin_subtest 'test runs if prerequisite is satisfied'
 test_set_prereq HAVEIT
 haveit=no
-test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
-    test_have_prereq HAVEIT &&
-    haveit=yes
-'
+test_expect_success 'test_have_prereq HAVEIT && haveit=yes'
 
+test_begin_subtest 'tests clean up after themselves'
 clean=no
-test_expect_success 'tests clean up after themselves' '
-    test_when_finished clean=yes
-'
+test_expect_success 'test_when_finished clean=yes'
 
+test_begin_subtest 'tests clean up even after a failure'
 cleaner=no
-test_expect_code 1 'tests clean up even after a failure' '
-    test_when_finished cleaner=yes &&
-    (exit 1)
-'
+test_expect_code 1 'test_when_finished cleaner=yes && (exit 1)'
 
 if test $clean$cleaner != yesyes
 then
@@ -45,9 +40,8 @@ then
        exit 1
 fi
 
-test_expect_code 2 'failure to clean up causes the test to fail' '
-    test_when_finished "(exit 2)"
-'
+test_begin_subtest 'failure to clean up causes the test to fail'
+test_expect_code 2 'test_when_finished "(exit 2)"'
 
 EXPECTED=$TEST_DIRECTORY/test.expected-output
 suppress_diff_date() {
@@ -72,19 +66,15 @@ test_expect_equal "$output" "$expected"
 ################################################################
 # Test mail store prepared in test-lib.sh
 
-test_expect_success \
-    'test that mail store was created' \
-    'test -d "${MAIL_DIR}"'
-
+test_begin_subtest 'test that mail store was created'
+test_expect_success 'test -d "${MAIL_DIR}"'
 
+test_begin_subtest 'mail store should be empty'
 find "${MAIL_DIR}" -type f -print >should-be-empty
-test_expect_success \
-    'mail store should be empty' \
-    'cmp -s /dev/null should-be-empty'
+test_expect_success 'cmp -s /dev/null should-be-empty'
 
-test_expect_success \
-    'NOTMUCH_CONFIG is set and points to an existing file' \
-    'test -f "${NOTMUCH_CONFIG}"'
+test_begin_subtest 'NOTMUCH_CONFIG is set and points to an existing file'
+test_expect_success 'test -f "${NOTMUCH_CONFIG}"'
 
 test_begin_subtest 'PATH is set to build directory'
 test_expect_equal \
index c173237631125ebd68894508763f1f61fab94d74..0c833de262170f5aea7b778aa62bcef0f9ed4d63 100755 (executable)
@@ -3,18 +3,27 @@
 test_description="online help"
 . ./test-lib.sh || exit 1
 
-test_expect_success 'notmuch --help' 'notmuch --help'
-test_expect_success 'notmuch help' 'notmuch help'
-test_expect_success 'notmuch --version' 'notmuch --version'
+test_begin_subtest 'notmuch --help'
+test_expect_success 'notmuch --help'
+
+test_begin_subtest 'notmuch help'
+test_expect_success 'notmuch help'
+
+test_begin_subtest 'notmuch --version'
+test_expect_success 'notmuch --version'
 
 if [ $NOTMUCH_HAVE_MAN -eq 1 ]; then
-    test_expect_success 'notmuch --help tag' 'notmuch --help tag'
-    test_expect_success 'notmuch help tag' 'notmuch help tag'
+    test_begin_subtest 'notmuch --help tag'
+    test_expect_success 'notmuch --help tag'
+
+    test_begin_subtest 'notmuch help tag'
+    test_expect_success 'notmuch help tag'
 else
-    test_expect_success 'notmuch --help tag (man pages not available)' \
-       'test_must_fail notmuch --help tag >/dev/null'
-    test_expect_success 'notmuch help tag (man pages not available)' \
-       'test_must_fail notmuch help tag >/dev/null'
+    test_begin_subtest 'notmuch --help tag (man pages not available)'
+    test_expect_success 'test_must_fail notmuch --help tag >/dev/null'
+
+    test_begin_subtest 'notmuch help tag (man pages not available)'
+    test_expect_success 'test_must_fail notmuch help tag >/dev/null'
 fi
 
 test_done
index 8b4dbbc481891e9cec748fa35cf9d5c6a1e0f029..a3d7380e81c8c12f1a685ca1f4e61cac292ea63c 100755 (executable)
@@ -16,12 +16,14 @@ if [ $NOTMUCH_HAVE_XAPIAN_COMPACT -eq 0 ]; then
     test_expect_equal "$output" "notmuch was compiled against a xapian version lacking compaction support.
 Compaction failed: Unsupported operation"
 
-    test_expect_code 1 "Compact unsupported: status code" "notmuch compact"
+    test_begin_subtest "Compact unsupported: status code"
+    test_expect_code 1 "notmuch compact"
 
     test_done
 fi
 
-test_expect_success "Running compact" "notmuch compact --backup=${TEST_DIRECTORY}/xapian.old"
+test_begin_subtest "Running compact"
+test_expect_success "notmuch compact --backup=${TEST_DIRECTORY}/xapian.old"
 
 test_begin_subtest "Compact preserves database"
 output=$(notmuch search \* | notmuch_search_sanitize)
@@ -30,8 +32,8 @@ thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 unread)
 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag2 unread)
 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Three (inbox tag3 unread)"
 
-test_expect_success 'Restoring Backup' \
-    'rm -Rf ${MAIL_DIR}/.notmuch/xapian &&
+test_begin_subtest "Restoring Backup"
+test_expect_success 'rm -Rf ${MAIL_DIR}/.notmuch/xapian &&
      mv ${TEST_DIRECTORY}/xapian.old ${MAIL_DIR}/.notmuch/xapian'
 
 test_begin_subtest "Checking restored backup"
index 9115de820770181bd6ff8f8c9b655d047e9fd8c9..ffa303efaceca99cdc7c0d6cbf75a83f6184bb1d 100755 (executable)
@@ -286,8 +286,8 @@ notmuch config set new.tags "-foo;bar"
 output=$(NOTMUCH_NEW --debug 2>&1)
 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
 
-test_expect_code 1 "Invalid tags set exit code" \
-    "NOTMUCH_NEW --debug 2>&1"
+test_begin_subtest "Invalid tags set exit code"
+test_expect_code 1 "NOTMUCH_NEW --debug 2>&1"
 
 notmuch config set new.tags $OLDCONFIG
 
index 9120debabf8c3f6ffe07c6d2b74a5cc17f746698..48f212ee09283f45468a405c55544223c31daf0f 100755 (executable)
@@ -20,13 +20,13 @@ gen_insert_msg() {
        "[body]=\"insert-message\""
 }
 
-test_expect_code 1 "Insert zero-length file" \
-    "notmuch insert < /dev/null"
+test_begin_subtest "Insert zero-length file"
+test_expect_code 1 "notmuch insert < /dev/null"
 
 # This test is a proxy for other errors that may occur while trying to
 # add a message to the notmuch database, e.g. database locked.
-test_expect_code 1 "Insert non-message" \
-    "echo bad_message | notmuch insert"
+test_begin_subtest "Insert non-message"
+test_expect_code 1 "echo bad_message | notmuch insert"
 
 test_begin_subtest "Database empty so far"
 test_expect_equal "0" "`notmuch count --output=messages '*'`"
@@ -138,9 +138,9 @@ notmuch insert --folder=Drafts +draft -unread < "$gen_msg_filename"
 output=$(notmuch search --output=messages path:Drafts/cur tag:draft NOT tag:unread)
 test_expect_equal "$output" "id:$gen_msg_id"
 
+test_begin_subtest "Insert message into non-existent folder"
 gen_insert_msg
-test_expect_code 1 "Insert message into non-existent folder" \
-    "notmuch insert --folder=nonesuch < $gen_msg_filename"
+test_expect_code 1 "notmuch insert --folder=nonesuch < $gen_msg_filename"
 
 test_begin_subtest "Insert message, create folder"
 gen_insert_msg
@@ -162,9 +162,9 @@ notmuch insert --folder=F/G/H/I/J --create-folder +folder < "$gen_msg_filename"
 output=$(notmuch count path:F/G/H/I/J/new tag:folder)
 test_expect_equal "$output" "2"
 
+test_begin_subtest "Insert message, create invalid subfolder"
 gen_insert_msg
-test_expect_code 1 "Insert message, create invalid subfolder" \
-    "notmuch insert --folder=../G --create-folder $gen_msg_filename"
+test_expect_code 1 "notmuch insert --folder=../G --create-folder $gen_msg_filename"
 
 OLDCONFIG=$(notmuch config get new.tags)
 
@@ -180,8 +180,8 @@ gen_insert_msg
 output=$(notmuch insert $gen_msg_filename 2>&1)
 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
 
-test_expect_code 1 "Invalid tags set exit code" \
-    "notmuch insert $gen_msg_filename 2>&1"
+test_begin_subtest "Invalid tags set exit code"
+test_expect_code 1 "notmuch insert $gen_msg_filename 2>&1"
 
 notmuch config set new.tags $OLDCONFIG
 
@@ -205,22 +205,28 @@ done
 gen_insert_msg
 
 for code in  FILE_NOT_EMAIL READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do
-    test_expect_code 1 "EXIT_FAILURE when add_message returns $code" \
+    test_begin_subtest "EXIT_FAILURE when add_message returns $code"
+    test_expect_code 1 \
          "${TEST_GDB} --batch-silent --return-child-result \
             -ex 'set args insert < $gen_msg_filename' \
             -x index-file-$code.gdb notmuch"
-    test_expect_code 0 "success exit with --keep when add_message returns $code" \
+
+    test_begin_subtest "success exit with --keep when add_message returns $code"
+    test_expect_code 0 \
          "${TEST_GDB} --batch-silent --return-child-result \
             -ex 'set args insert --keep < $gen_msg_filename' \
             -x index-file-$code.gdb notmuch"
 done
 
 for code in OUT_OF_MEMORY XAPIAN_EXCEPTION ; do
-    test_expect_code 75 "EX_TEMPFAIL when add_message returns $code" \
+    test_begin_subtest "EX_TEMPFAIL when add_message returns $code"
+    test_expect_code 75 \
          "${TEST_GDB} --batch-silent --return-child-result \
             -ex 'set args insert < $gen_msg_filename' \
             -x index-file-$code.gdb notmuch"
-    test_expect_code 0 "success exit with --keep when add_message returns $code" \
+
+    test_begin_subtest "success exit with --keep when add_message returns $code"
+    test_expect_code 0 \
          "${TEST_GDB} --batch-silent --return-child-result \
             -ex 'set args insert --keep < $gen_msg_filename' \
             -x index-file-$code.gdb notmuch"
index 61d1311608a755c5815bf545ff46170036339fa5..0d0a3b874526dccd24166066be3767fbe29efea5 100755 (executable)
@@ -19,8 +19,11 @@ test_expect_equal "$output" "\
 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag3 unread)
 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag3 unread)"
 
-test_expect_code 1 "No tag operations" 'notmuch tag One'
-test_expect_code 1 "No query" 'notmuch tag +tag2'
+test_begin_subtest "No tag operations"
+test_expect_code 1 'notmuch tag One'
+
+test_begin_subtest "No query"
+test_expect_code 1 'notmuch tag +tag2'
 
 test_begin_subtest "Redundant tagging"
 notmuch tag +tag1 -tag3 One
@@ -282,9 +285,11 @@ notmuch dump --format=batch-tag| \
 
 test_expect_equal_file EXPECTED OUTPUT
 
-test_expect_code 1 "Empty tag names" 'notmuch tag + One'
+test_begin_subtest "Empty tag names"
+test_expect_code 1 'notmuch tag + One'
 
-test_expect_code 1 "Tag name beginning with -" 'notmuch tag +- One'
+test_begin_subtest "Tag name beginning with -"
+test_expect_code 1 'notmuch tag +- One'
 
 test_begin_subtest "Xapian exception: read only files"
 chmod u-w  ${MAIL_DIR}/.notmuch/xapian/*.${db_ending}
index 5a954e3baf0d477e26bc570985c768fc7c20a10c..ac51895e826d260601260d6aae1a55bb90138fa9 100755 (executable)
@@ -64,11 +64,11 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
  \"tags\": [\"inbox\",
  \"unread\"]}]"
 
-test_expect_code 20 "Format version: too low" \
-    "notmuch search --format-version=0 \\*"
+test_begin_subtest "Format version: too low"
+test_expect_code 20 "notmuch search --format-version=0 \\*"
 
-test_expect_code 21 "Format version: too high" \
-    "notmuch search --format-version=999 \\*"
+test_begin_subtest "Format version: too high"
+test_expect_code 21 "notmuch search --format-version=999 \\*"
 
 test_begin_subtest "Show message: multiple filenames"
 add_message "[id]=message-id@example.com [filename]=copy1"
index a31d61e2aa20bd77850783a7e27e7c477e9494d1..a6b155e9c7a82d0ca3b15b8457ef132f7c482a74 100755 (executable)
@@ -338,9 +338,8 @@ Non-text part: application/pgp-signature
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
-test_expect_success \
-    "--format=text --part=8, no part, expect error" \
-    "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
+test_begin_subtest "--format=text --part=8, no part, expect error"
+test_expect_success "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
 
 test_begin_subtest "--format=json --part=0, full message"
 notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
@@ -444,9 +443,8 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
 
-test_expect_success \
-    "--format=json --part=10, no part, expect error" \
-    "notmuch show --format=json --part=10 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
+test_begin_subtest "--format=json --part=10, no part, expect error"
+test_expect_success "notmuch show --format=json --part=10 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
 
 test_begin_subtest "--format=raw"
 notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
@@ -580,9 +578,8 @@ W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
-test_expect_success \
-    "--format=raw --part=10, no part, expect error" \
-    "notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
+test_begin_subtest "--format=raw --part=10, no part, expect error"
+test_expect_success "notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
 
 test_begin_subtest "--format=mbox"
 notmuch show --format=mbox 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
@@ -592,9 +589,8 @@ cat "${MAIL_DIR}"/multipart >>EXPECTED
 echo >>EXPECTED
 test_expect_equal_file OUTPUT EXPECTED
 
-test_expect_success \
-    "--format=mbox --part=1, incompatible, expect error" \
-    "! notmuch show --format=mbox --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
+test_begin_subtest "--format=mbox --part=1, incompatible, expect error"
+test_expect_success "! notmuch show --format=mbox --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
 
 test_begin_subtest "'notmuch reply' to a multipart message"
 notmuch reply 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
index faa10364acf52a19a9553ebe515b4bb01bd81b61..206c3ae14560c9e3436ecc6e5e01f8bce48c0cdc 100755 (executable)
@@ -4,52 +4,58 @@ test_description="\"notmuch dump\" and \"notmuch restore\""
 
 add_email_corpus
 
-test_expect_success 'Dumping all tags' \
-  'generate_message &&
-  notmuch new &&
-  notmuch dump > dump.expected'
+test_begin_subtest "Dumping all tags"
+test_expect_success 'generate_message && notmuch new && notmuch dump > dump.expected'
 
 # The use of from:cworth is rather arbitrary: it matches some of the
 # email corpus' messages, but not all of them.
 
-test_expect_success 'Dumping all tags II' \
+test_begin_subtest "Dumping all tags II"
+test_expect_success \
   'notmuch tag +ABC +DEF -- from:cworth &&
   notmuch dump > dump-ABC_DEF.expected &&
   ! cmp dump.expected dump-ABC_DEF.expected'
 
-test_expect_success 'Clearing all tags' \
+test_begin_subtest "Clearing all tags"
+test_expect_success \
   'sed -e "s/(\([^(]*\))$/()/" < dump.expected > clear.expected &&
   notmuch restore --input=clear.expected &&
   notmuch dump > clear.actual &&
   test_cmp clear.expected clear.actual'
 
-test_expect_success 'Accumulate original tags' \
+test_begin_subtest "Clearing all tags"
+test_expect_success \
   'notmuch tag +ABC +DEF -- from:cworth &&
   notmuch restore --accumulate < dump.expected &&
   notmuch dump > dump.actual &&
   test_cmp dump-ABC_DEF.expected dump.actual'
 
-test_expect_success 'Restoring original tags' \
+test_begin_subtest "Restoring original tags"
+test_expect_success \
   'notmuch restore --input=dump.expected &&
   notmuch dump > dump.actual &&
   test_cmp dump.expected dump.actual'
 
-test_expect_success 'Restore with nothing to do' \
+test_begin_subtest "Restore with nothing to do"
+test_expect_success \
   'notmuch restore < dump.expected &&
   notmuch dump > dump.actual &&
   test_cmp dump.expected dump.actual'
 
-test_expect_success 'Accumulate with existing tags' \
+test_begin_subtest "Accumulate with existing tags"
+test_expect_success \
   'notmuch restore --accumulate --input=dump.expected &&
   notmuch dump > dump.actual &&
   test_cmp dump.expected dump.actual'
 
-test_expect_success 'Accumulate with no tags' \
+test_begin_subtest "Accumulate with no tags"
+test_expect_success \
   'notmuch restore --accumulate < clear.expected &&
   notmuch dump > dump.actual &&
   test_cmp dump.expected dump.actual'
 
-test_expect_success 'Accumulate with new tags' \
+test_begin_subtest "Accumulate with new tags"
+test_expect_success \
   'notmuch restore --input=dump.expected &&
   notmuch restore --accumulate --input=dump-ABC_DEF.expected &&
   notmuch dump >  OUTPUT.$test_count &&
@@ -57,7 +63,8 @@ test_expect_success 'Accumulate with new tags' \
   test_cmp dump-ABC_DEF.expected OUTPUT.$test_count'
 
 # notmuch restore currently only considers the first argument.
-test_expect_success 'Invalid restore invocation' \
+test_begin_subtest "Invalid restore invocation"
+test_expect_success \
   'test_must_fail notmuch restore --input=dump.expected another_one'
 
 test_begin_subtest "dump --output=outfile"
index f626d9a7b7f2b7e3f5beca18fb92f513f11656ce..4ca081c87daa2f79e1a6b320a38d1ec85e6d8bdc 100755 (executable)
@@ -8,8 +8,8 @@ EXPECTED=$TEST_DIRECTORY/emacs.expected-output
 add_email_corpus
 
 # syntax errors in test-lib.el cause mysterious failures
-test_expect_success 'Syntax of emacs test library' \
-    "${TEST_EMACS} -Q --batch --load $TEST_DIRECTORY/test-lib.el"
+test_begin_subtest "Syntax of emacs test library"
+test_expect_success "${TEST_EMACS} -Q --batch --load $TEST_DIRECTORY/test-lib.el"
 
 test_begin_subtest "Basic notmuch-hello view in emacs"
 test_emacs '(notmuch-hello)
@@ -983,9 +983,8 @@ test_emacs "(let ((mm-text-html-renderer
 # Different Emacs versions and renderers give very different results,
 # so just check that something reasonable showed up.  We first cat the
 # output so the test framework will print it if the test fails.
-test_expect_success "Rendering HTML mail with images" \
-    'cat OUTPUT && grep -q smiley OUTPUT'
-
+test_begin_subtest "Rendering HTML mail with images"
+test_expect_success 'cat OUTPUT && grep -q smiley OUTPUT'
 
 test_begin_subtest "Search handles subprocess error exit codes"
 cat > notmuch_fail <<EOF
index b474bf46e4be4ac6c51f4913d35b4c977bd4726e..6d9566354bb32b1b3705dcf6daeb993dc39fa29c 100755 (executable)
@@ -52,7 +52,8 @@ test_expect_equal_json "$output" '[[[{"id": "XXXXX",
 "content": "This is just a test message (#3)\n"}]},
 []]]]'
 
-test_expect_success 'notmuch reply works with renamed file (without notmuch new)' 'notmuch reply id:${gen_msg_id}'
+test_begin_subtest "notmuch reply works with renamed file (without notmuch new)"
+test_expect_success 'notmuch reply id:${gen_msg_id}'
 
 test_begin_subtest "notmuch new detects no file rename after tag->flag synchronization"
 output=$(NOTMUCH_NEW)
@@ -123,9 +124,10 @@ output+=$(notmuch search subject:"Message to lose maildir info" | notmuch_search
 test_expect_equal "$output" "No new mail. Detected 1 file rename.
 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox)"
 
+test_begin_subtest "Can remove unread tag from message in non-maildir directory"
 add_message [subject]='"Non-maildir message"' [dir]=notmaildir [filename]='non-maildir-message'
 expected=$(notmuch search --output=files subject:"Non-maildir message")
-test_expect_success "Can remove unread tag from message in non-maildir directory" 'notmuch tag -unread subject:"Non-maildir message"'
+test_expect_success 'notmuch tag -unread subject:"Non-maildir message"'
 
 test_begin_subtest "Message in non-maildir directory does not get renamed"
 output=$(notmuch search --output=files subject:"Non-maildir message")
index b15f4fbe77608b3d5d5189fd28307584b0a9aea4..3cf644df6fac781dc33a75804494a82522adad3e 100755 (executable)
@@ -28,7 +28,8 @@ add_gnupg_home
 # Change this if we ship a new test key
 FINGERPRINT="5AEAB11F5E33DCE875DDB75B6D92612D94E46381"
 
-test_expect_success 'emacs delivery of signed message' \
+test_begin_subtest "emacs delivery of signed message"
+test_expect_success \
 'emacs_fcc_message \
     "test signed message 001" \
     "This is a test signed message." \
@@ -134,11 +135,12 @@ test_expect_equal_json \
     "$expected"
 mv "${GNUPGHOME}"{.bak,}
 
+test_begin_subtest "emacs delivery of encrypted message with attachment"
 # create a test encrypted message with attachment
 cat <<EOF >TESTATTACHMENT
 This is a test file.
 EOF
-test_expect_success 'emacs delivery of encrypted message with attachment' \
+test_expect_success \
 'emacs_fcc_message \
     "test encrypted message 001" \
     "This is a test encrypted message.\n" \
@@ -264,7 +266,8 @@ test_expect_equal_json \
     "$expected"
 mv "${GNUPGHOME}"{.bak,}
 
-test_expect_success 'emacs delivery of encrypted + signed message' \
+test_begin_subtest "emacs delivery of encrypted + signed message"
+test_expect_success \
 'emacs_fcc_message \
     "test encrypted message 002" \
     "This is another test encrypted message.\n" \
index 1efefcbd7a239ebbcf1461fe07e2d08c0bf47eab..639ca697c734f6e5f82d51a522fe756a6c40eac9 100755 (executable)
@@ -23,14 +23,16 @@ FINGERPRINT=$(openssl x509 -fingerprint -in test_suite.pem -noout | sed -e 's/^.
 
 add_gpgsm_home
 
-test_expect_success 'emacs delivery of S/MIME signed message' \
+test_begin_subtest "emacs delivery of S/MIME signed message"
+test_expect_success \
      'emacs_fcc_message \
      "test signed message 001" \
      "This is a test signed message." \
      "(mml-secure-message-sign \"smime\")"'
 
+test_begin_subtest "emacs delivery of S/MIME encrypted + signed message"
 # Hard code the MML to avoid several interactive questions
-test_expect_success 'emacs delivery of S/MIME encrypted + signed message' \
+test_expect_success \
 'emacs_fcc_message \
     "test encrypted message 001" \
     "<#secure method=smime mode=signencrypt keyfile=\\\"test_suite.pem\\\" certfile=\\\"test_suite.pem\\\">\nThis is a test encrypted message.\n"'
index c6a9fb980bf0d4678a444939f5bb97ddd957747a..a46a2df2a1febb740a0e5bd180da97224e0677ba 100755 (executable)
@@ -95,6 +95,7 @@ fi
 test_begin_subtest '"notmuch new" is idempotent under arbitrary aborts'
 test_expect_equal_file searchall expectall
 
-test_expect_success "detected $outcount>10 abort points" "test $outcount -gt 10"
+test_begin_subtest "detected $outcount>10 abort points"
+test_expect_success "test $outcount -gt 10"
 
 test_done
index 4726bc366ecebda8fc48e694ad802403ea4c6807..b27f0740edfb75bfa84ba7e0f977cee670d98fce 100755 (executable)
@@ -38,4 +38,23 @@ print (db.find_message_by_filename("i-dont-exist"))
 EOF
 test_expect_equal "$(cat OUTPUT)" "None"
 
+test_begin_subtest "get revision"
+test_python ${MAIL_DIR} <<'EOF'
+import notmuch
+db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
+(revision, uuid) = db.get_revision()
+print ("%s\t%lu" % (uuid, revision))
+EOF
+notmuch_uuid_sanitize < OUTPUT > CLEAN
+cat <<'EOF' >EXPECTED
+UUID   53
+EOF
+test_expect_equal_file EXPECTED CLEAN
+
+grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
+
+test_begin_subtest "output of count matches test code"
+notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
+test_expect_equal_file INITIAL_OUTPUT OUTPUT
+
 test_done
index ed1191319fecbf49f681b0f46ee4a197a45ccdee..7917a82f0154ef1d8355e62d7ae30ebb796e3fa8 100755 (executable)
@@ -70,7 +70,8 @@ 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"
+test_begin_subtest "pre-new non-zero exit status (notmuch status)"
+test_expect_code 1 "notmuch new"
 
 # depends on the previous subtests leaving 1 new message behind
 test_begin_subtest "pre-new non-zero exit status aborts new"
@@ -89,15 +90,16 @@ 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 "post-new non-zero exit status (notmuch status)"
+test_expect_code 1 "notmuch new"
 
+test_begin_subtest "post-insert hook does not affect insert status"
 rm_hooks
 generate_message
 create_failing_hook "post-insert"
-test_expect_success "post-insert hook does not affect insert status" \
-    "notmuch insert < \"$gen_msg_filename\" > /dev/null"
+test_expect_success "notmuch insert < \"$gen_msg_filename\" > /dev/null"
 
-test_begin_subtest "hook without executable permissions"
+test_begin_subtest "hook without executable permissions"
 rm_hooks
 mkdir -p ${HOOK_DIR}
 cat <<EOF >"${HOOK_DIR}/pre-new"
@@ -105,15 +107,15 @@ cat <<EOF >"${HOOK_DIR}/pre-new"
 echo foo
 EOF
 output=`notmuch new 2>&1`
-test_expect_code 1 "hook without executable permissions" "notmuch new"
+test_expect_code 1 "notmuch new"
 
-test_begin_subtest "hook execution failure"
+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_expect_code 1 "notmuch new"
 
 test_done
index a3a7d39c5251acd32edc987041596bb4601e40db..f0fd1511d0567f99fd0ab027a8e627441855431e 100755 (executable)
@@ -10,8 +10,8 @@ if [ ! -e ${TEST_DIRECTORY}/test-databases/${dbtarball} ]; then
     test_subtest_missing_external_prereq_["${dbtarball} - fetch with 'make download-test-databases'"]=t
 fi
 
+test_begin_subtest "database checksum"
 test_expect_success \
-    'database checksum' \
     '( cd $TEST_DIRECTORY/test-databases &&
        sha256sum --quiet --check --status ${dbtarball}.sha256 )'
 
@@ -25,7 +25,8 @@ test_begin_subtest "path: search does not work with old database version"
 output=$(notmuch search path:foo)
 test_expect_equal "$output" ""
 
-test_expect_success 'pre upgrade dump' 'notmuch dump | sort > pre-upgrade-dump'
+test_begin_subtest "pre upgrade dump"
+test_expect_success 'notmuch dump | sort > pre-upgrade-dump'
 
 test_begin_subtest "database upgrade from format version 1"
 output=$(notmuch new | sed -e 's/^Backing up tags to .*$/Backing up tags to FILENAME/')
index 087c6bd74707736384994f71d8720e2539475233..e775216ee29bd47ff55f31fa03a202580c663eea 100755 (executable)
@@ -5,7 +5,8 @@ test_description="error reporting for library"
 
 add_email_corpus
 
-test_expect_success "building database" "NOTMUCH_NEW"
+test_begin_subtest "building database"
+test_expect_success "NOTMUCH_NEW"
 
 test_begin_subtest "Open null pointer"
 test_C <<'EOF'
index 0936011ae6a1e50e3611d74846653afcffa5bf2f..76ad227944a0636b53168c8c0afd401dc26ef767 100755 (executable)
@@ -49,29 +49,29 @@ test_expect_equal 1 ${result}
 
 notmuch count --lastmod '*' | cut -f2 > UUID
 
-test_expect_success 'search succeeds with correct uuid' \
-                   "notmuch search --uuid=$(cat UUID) '*'"
+test_begin_subtest "search succeeds with correct uuid"
+test_expect_success "notmuch search --uuid=$(cat UUID) '*'"
 
-test_expect_success 'uuid works as global option ' \
-                   "notmuch --uuid=$(cat UUID) search '*'"
+test_begin_subtest "uuid works as global option"
+test_expect_success "notmuch --uuid=$(cat UUID) search '*'"
 
-test_expect_code 1 'uuid works as global option II' \
-                   "notmuch --uuid=this-is-no-uuid search '*'"
+test_begin_subtest "uuid works as global option II"
+test_expect_code 1 "notmuch --uuid=this-is-no-uuid search '*'"
 
-test_expect_code 1 'search fails with incorrect uuid' \
-                "notmuch search --uuid=this-is-no-uuid '*'"
+test_begin_subtest "search fails with incorrect uuid"
+test_expect_code 1 "notmuch search --uuid=this-is-no-uuid '*'"
 
-test_expect_success 'show succeeds with correct uuid' \
-                   "notmuch show --uuid=$(cat UUID) '*'"
+test_begin_subtest "show succeeds with correct uuid"
+test_expect_success "notmuch show --uuid=$(cat UUID) '*'"
 
-test_expect_code 1 'show fails with incorrect uuid' \
-                "notmuch show --uuid=this-is-no-uuid '*'"
+test_begin_subtest "show fails with incorrect uuid"
+test_expect_code 1 "notmuch show --uuid=this-is-no-uuid '*'"
 
-test_expect_success 'tag succeeds with correct uuid' \
-                   "notmuch tag --uuid=$(cat UUID) +test '*'"
+test_begin_subtest "tag succeeds with correct uuid"
+test_expect_success "notmuch tag --uuid=$(cat UUID) +test '*'"
 
-test_expect_code 1 'tag fails with incorrect uuid' \
-                "notmuch tag --uuid=this-is-no-uuid '*' +test2"
+test_begin_subtest "tag fails with incorrect uuid"
+test_expect_code 1 "notmuch tag --uuid=this-is-no-uuid '*' +test2"
 
 test_begin_subtest 'lastmod:0.. matches everything'
 total=$(notmuch count '*')
index f0ae24f1a5fb4662431739b76123d9fcc24aca46..495b7699a0a781beee246fb6070bdb67e3ae584d 100755 (executable)
@@ -4,17 +4,17 @@ test_description='named queries'
 
 QUERYSTR="date:2009-11-18..2009-11-18 and tag:unread"
 
-test_expect_code 1 "error adding named query before initializing DB" \
-                "notmuch config set query.test \"$QUERYSTR\""
+test_begin_subtest "error adding named query before initializing DB"
+test_expect_code 1 "notmuch config set query.test \"$QUERYSTR\""
 
 add_email_corpus
 
-test_expect_success "adding named query" \
-                   "notmuch config set query.test \"$QUERYSTR\""
+test_begin_subtest "adding named query"
+test_expect_success "notmuch config set query.test \"$QUERYSTR\""
 
+test_begin_subtest "adding nested named query"
 QUERYSTR2="query:test and subject:Maildir"
-test_expect_success "adding nested named query" \
-                   "notmuch config set query.test2 \"$QUERYSTR2\""
+test_expect_success "notmuch config set query.test2 \"$QUERYSTR2\""
 
 test_begin_subtest "retrieve named query"
 output=$(notmuch config get query.test)
diff --git a/test/T660-bad-date.sh b/test/T660-bad-date.sh
new file mode 100755 (executable)
index 0000000..a98e11c
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+test_description="parsing of bad dates"
+. ./test-lib.sh || exit 1
+
+add_message [date]='"()"'
+
+test_begin_subtest 'Bad dates translate to a date after the Unix epoch'
+cat <<EOF >EXPECTED
+thread:0000000000000001   1970-01-01 [1/1] Notmuch Test Suite; Test message #1 (inbox unread)
+EOF
+notmuch search '*' > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_done
index 1ca52b9c4f73aad5966e44e3dff8505b1d9e348f..389517e1571e0b6590d068ef9cc9c13a98b44a40 100644 (file)
@@ -71,4 +71,8 @@ class RenameBreakpoint(gdb.Breakpoint):
         return False
 RenameBreakpoint('rename')
 
-gdb.execute('run')
+try:
+    gdb.execute('run')
+except Exception:
+    import traceback
+    raise SystemExit(traceback.format_exc())
index dcc8863c70d8ee973687eb30580e02640e214f3e..7aedff70f6e3df4114f62d32f605d37645d851ca 100644 (file)
@@ -7,7 +7,13 @@ dir := test/test-databases
 test_databases := $(dir)/database-v1.tar.xz
 
 %.tar.xz:
-       wget -nv -O $@ ${TEST_DATABASE_MIRROR}/$(notdir $@);
+       @exec 1>&2 ;\
+       if command -v wget >/dev/null ;\
+       then set -x; wget -nv -O $@ ${TEST_DATABASE_MIRROR}/$(notdir $@) ;\
+       elif command -v curl >/dev/null ;\
+       then set -x; curl -L -s -o $@ ${TEST_DATABASE_MIRROR}/$(notdir $@) ;\
+       else echo Cannot fetch databases, no wget nor curl available; exit 1 ;\
+       fi
 
 download-test-databases: ${test_databases}
 
index 02634ac1cebc88bb1673c88495f427bca82aef7a..988b00afde86b7ff306c2b0812d9b7e6fa0a0428 100644 (file)
@@ -93,15 +93,6 @@ unset GREP_OPTIONS
 # For emacsclient
 unset ALTERNATE_EDITOR
 
-# Convenience
-#
-# A regexp to match 5 and 40 hexdigits
-_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
-_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
-
-_x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
-_x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
-
 # Each test should start with something like this, after copyright notices:
 #
 # test_description='Description of this test...
@@ -122,17 +113,15 @@ _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
 while test "$#" -ne 0
 do
        case "$1" in
-       -d|--d|--de|--deb|--debu|--debug)
+       -d|--debug)
                debug=t; shift ;;
-       -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
+       -i|--immediate)
                immediate=t; shift ;;
-       -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
-               GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
-       -h|--h|--he|--hel|--help)
+       -h|--help)
                help=t; shift ;;
-       -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
+       -v|--verbose)
                verbose=t; shift ;;
-       -q|--q|--qu|--qui|--quie|--quiet)
+       -q|--quiet)
                quiet=t; shift ;;
        --with-dashes)
                with_dashes=t; shift ;;
@@ -141,7 +130,7 @@ do
        --no-python)
                # noop now...
                shift ;;
-       --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
+       --valgrind)
                valgrind=t; verbose=t; shift ;;
        --tee)
                shift ;; # was handled already
@@ -276,33 +265,6 @@ export GNUPGHOME="${TEST_TMPDIR}/gnupg"
 trap 'trap_exit' EXIT
 trap 'trap_signal' HUP INT TERM
 
-test_decode_color () {
-       sed     -e 's/.\[1m/<WHITE>/g' \
-               -e 's/.\[31m/<RED>/g' \
-               -e 's/.\[32m/<GREEN>/g' \
-               -e 's/.\[33m/<YELLOW>/g' \
-               -e 's/.\[34m/<BLUE>/g' \
-               -e 's/.\[35m/<MAGENTA>/g' \
-               -e 's/.\[36m/<CYAN>/g' \
-               -e 's/.\[m/<RESET>/g'
-}
-
-q_to_nul () {
-       perl -pe 'y/Q/\000/'
-}
-
-q_to_cr () {
-       tr Q '\015'
-}
-
-append_cr () {
-       sed -e 's/$/Q/' | tr Q '\015'
-}
-
-remove_cr () {
-       tr '\015' Q | sed -e 's/Q$//'
-}
-
 # Generate a new message in the mail directory, with a unique message
 # ID and subject. The message is not added to the index.
 #
@@ -597,10 +559,12 @@ test_begin_subtest ()
 test_expect_equal ()
 {
        exec 1>&6 2>&7          # Restore stdout and stderr
+       if [ -z "$inside_subtest" ]; then
+               error "bug in the test script: test_expect_equal without test_begin_subtest"
+       fi
        inside_subtest=
-       test "$#" = 3 && { prereq=$1; shift; } || prereq=
        test "$#" = 2 ||
-       error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
+       error "bug in the test script: not 2 parameters to test_expect_equal"
 
        output="$1"
        expected="$2"
@@ -621,10 +585,12 @@ test_expect_equal ()
 test_expect_equal_file ()
 {
        exec 1>&6 2>&7          # Restore stdout and stderr
+       if [ -z "$inside_subtest" ]; then
+               error "bug in the test script: test_expect_equal_file without test_begin_subtest"
+       fi
        inside_subtest=
-       test "$#" = 3 && { prereq=$1; shift; } || prereq=
        test "$#" = 2 ||
-       error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
+       error "bug in the test script: not 2 parameters to test_expect_equal_file"
 
        file1="$1"
        file2="$2"
@@ -665,9 +631,11 @@ test_sort_json () {
 }
 
 test_emacs_expect_t () {
-       test "$#" = 2 && { prereq=$1; shift; } || prereq=
        test "$#" = 1 ||
-       error "bug in the test script: not 1 or 2 parameters to test_emacs_expect_t"
+       error "bug in the test script: not 1 parameter to test_emacs_expect_t"
+       if [ -z "$inside_subtest" ]; then
+               error "bug in the test script: test_emacs_expect_t without test_begin_subtest"
+       fi
 
        # Run the test.
        if ! test_skip "$test_subtest_name"
@@ -779,12 +747,8 @@ notmuch_config_sanitize ()
 # End of notmuch helper functions
 
 # Use test_set_prereq to tell that a particular prerequisite is available.
-# The prerequisite can later be checked for in two ways:
 #
-# - Explicitly using test_have_prereq.
-#
-# - Implicitly by specifying the prerequisite tag in the calls to
-#   test_expect_{success,failure,code}.
+# The prerequisite can later be checked for by using test_have_prereq.
 #
 # The single parameter is the prerequisite tag (a simple word, in all
 # capital letters by convention).
@@ -851,12 +815,12 @@ test_ok_ () {
 }
 
 test_failure_ () {
+       print_test_description
        if test "$test_subtest_known_broken_" = "t"; then
                test_known_broken_failure_ "$@"
                return
        fi
        test_failure=$(($test_failure + 1))
-       print_test_description
        test_failure_message_ "FAIL" "$test_subtest_name" "$@"
        test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
        return 1
@@ -866,7 +830,9 @@ test_failure_message_ () {
        say_color error "%-6s" "$1"
        echo " $2"
        shift 2
-       echo "$@" | sed -e 's/^/        /'
+       if [ "$#" != "0" ]; then
+               echo "$@" | sed -e 's/^/        /'
+       fi
        if test "$verbose" != "t"; then cat test.output; fi
 }
 
@@ -880,7 +846,11 @@ test_known_broken_ok_ () {
 test_known_broken_failure_ () {
        test_reset_state_
        test_broken=$(($test_broken+1))
-       test_failure_message_ "BROKEN" "$test_subtest_name" "$@"
+       if [ -z "$NOTMUCH_TEST_QUIET" ]; then
+               test_failure_message_ "BROKEN" "$test_subtest_name" "$@"
+       else
+               test_failure_message_ "BROKEN" "$test_subtest_name"
+       fi
        return 1
 }
 
@@ -913,11 +883,6 @@ test_skip () {
                        break
                esac
        done
-       if test -z "$to_skip" && test -n "$prereq" &&
-          ! test_have_prereq "$prereq"
-       then
-               to_skip=t
-       fi
        case "$to_skip" in
        t)
                test_report_skip_ "$@"
@@ -951,14 +916,17 @@ test_subtest_known_broken () {
 }
 
 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_subtest_name="$1"
-       test_reset_state_
-       if ! test_skip "$@"
+       exec 1>&6 2>&7          # Restore stdout and stderr
+       if [ -z "$inside_subtest" ]; then
+               error "bug in the test script: test_expect_success without test_begin_subtest"
+       fi
+       inside_subtest=
+       test "$#" = 1 ||
+       error "bug in the test script: not 1 parameters to test_expect_success"
+
+       if ! test_skip "$test_subtest_name"
        then
-               test_run_ "$2"
+               test_run_ "$1"
                run_ret="$?"
                # test_run_ may update missing external prerequisites
                test_check_missing_external_prereqs_ "$@" ||
@@ -966,20 +934,23 @@ test_expect_success () {
                then
                        test_ok_
                else
-                       test_failure_ "$2"
+                       test_failure_ "$1"
                fi
        fi
 }
 
 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_subtest_name="$2"
-       test_reset_state_
-       if ! test_skip "$@"
+       exec 1>&6 2>&7          # Restore stdout and stderr
+       if [ -z "$inside_subtest" ]; then
+               error "bug in the test script: test_expect_code without test_begin_subtest"
+       fi
+       inside_subtest=
+       test "$#" = 2 ||
+       error "bug in the test script: not 2 parameters to test_expect_code"
+
+       if ! test_skip "$test_subtest_name"
        then
-               test_run_ "$3"
+               test_run_ "$2"
                run_ret="$?"
                # test_run_ may update missing external prerequisites,
                test_check_missing_external_prereqs_ "$@" ||
@@ -987,67 +958,8 @@ test_expect_code () {
                then
                        test_ok_
                else
-                       test_failure_ "exit code $eval_ret, expected $1" "$3"
-               fi
-       fi
-}
-
-# test_external runs external test scripts that provide continuous
-# test output about their progress, and succeeds/fails on
-# zero/non-zero exit code.  It outputs the test output on stdout even
-# in non-verbose mode, and announces the external script with "* run
-# <n>: ..." before running it.  When providing relative paths, keep in
-# mind that all scripts run in "trash directory".
-# Usage: test_external description command arguments...
-# Example: test_external 'Perl API' perl ../path/to/test.pl
-test_external () {
-       test "$#" = 4 && { prereq=$1; shift; } || prereq=
-       test "$#" = 3 ||
-       error >&6 "bug in the test script: not 3 or 4 parameters to test_external"
-       test_subtest_name="$1"
-       shift
-       test_reset_state_
-       if ! test_skip "$test_subtest_name" "$@"
-       then
-               # Announce the script to reduce confusion about the
-               # test output that follows.
-               say_color "" " run $test_count: $descr ($*)"
-               # Run command; redirect its stderr to &4 as in
-               # test_run_, but keep its stdout on our stdout even in
-               # non-verbose mode.
-               "$@" 2>&4
-               if [ "$?" = 0 ]
-               then
-                       test_ok_
-               else
-                       test_failure_ "$@"
-               fi
-       fi
-}
-
-# Like test_external, but in addition tests that the command generated
-# no output on stderr.
-test_external_without_stderr () {
-       # The temporary file has no (and must have no) security
-       # implications.
-       tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
-       stderr="$tmp/git-external-stderr.$$.tmp"
-       test_external "$@" 4> "$stderr"
-       [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
-       test_subtest_name="no stderr: $1"
-       shift
-       if [ ! -s "$stderr" ]; then
-               rm "$stderr"
-               test_ok_
-       else
-               if [ "$verbose" = t ]; then
-                       output=`echo; echo Stderr is:; cat "$stderr"`
-               else
-                       output=
+                       test_failure_ "exit code $eval_ret, expected $1" "$2"
                fi
-               # rm first in case test_failure exits.
-               rm "$stderr"
-               test_failure_ "$@" "$output"
        fi
 }
 
@@ -1209,7 +1121,7 @@ test_emacs () {
 test_python() {
     # Note: if there is need to print debug information from python program,
     # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
-    PYTHONPATH="$TEST_DIRECTORY/../bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
+    PYTHONPATH="$NOTMUCH_SRCDIR/bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
        $NOTMUCH_PYTHON -B - > OUTPUT
 }
 
@@ -1221,7 +1133,7 @@ test_C () {
     exec_file="test${test_count}"
     test_file="${exec_file}.c"
     cat > ${test_file}
-    ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
+    ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${NOTMUCH_SRCDIR}/lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
     echo "== stdout ==" > OUTPUT.stdout
     echo "== stderr ==" > OUTPUT.stderr
     ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
index 1723ce665caa73287c4ae5dced5099786626c15b..158be28a365eaef601efea2209ab07bcafce8622 100755 (executable)
@@ -4,12 +4,14 @@ test_description='the verbosity options of the test framework itself.'
 
 . ./test-lib.sh || exit 1
 
-test_expect_success 'print something in test_expect_success and pass' '
+test_begin_subtest 'print something in test_expect_success and pass'
+test_expect_success '
   echo "hello stdout" &&
   echo "hello stderr" >&2 &&
   true
 '
-test_expect_success 'print something in test_expect_success and fail' '
+test_begin_subtest 'print something in test_expect_success and fail'
+test_expect_success '
   echo "hello stdout" &&
   echo "hello stderr" >&2 &&
   false