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,"
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
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
_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)]
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
require 'mkmf'
-dir = File.join('..', '..', 'lib')
+dir = File.join(ENV['NOTMUCH_SRCDIR'], 'lib')
# includes
$INCFLAGS = "-I#{dir} #{$INCFLAGS}"
# 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"
# 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
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
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
# 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}
# 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}
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). */
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 *
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;
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)
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;
#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)
{
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 */
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 },
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 ();
/* 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) {
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");
}
/* 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, ¶ms);
- else {
+ if (single_message) {
+ ret = do_show_single (config, query, formatter, sprinter, ¶ms);
+ } 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 */
params.omit_excluded = FALSE;
}
- ret = do_show (config, query, format, sprinter, ¶ms);
+ ret = do_show (config, query, formatter, sprinter, ¶ms);
}
notmuch_crypto_cleanup (¶ms.crypto);
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.
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
################################################################
# 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
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() {
################################################################
# 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 \
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
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)
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"
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
"[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 '*'`"
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
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)
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
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"
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
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}
\"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"
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
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
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
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
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 &&
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"
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)
# 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
"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)
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")
# 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." \
"$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" \
"$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" \
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"'
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
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
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"
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"
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
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 )'
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/')
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'
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 '*')
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)
return False
RenameBreakpoint('rename')
-gdb.execute('run')
+try:
+ gdb.execute('run')
+except Exception:
+ import traceback
+ raise SystemExit(traceback.format_exc())
# 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...
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 ;;
--no-python)
# noop now...
shift ;;
- --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
+ --valgrind)
valgrind=t; verbose=t; shift ;;
--tee)
shift ;; # was handled already
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.
#
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"
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"
}
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"
# 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).
}
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
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
}
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
}
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_ "$@"
}
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_ "$@" ||
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_ "$@" ||
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
}
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
}
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
. ./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