--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 4174B429E39\r
+ for <notmuch@notmuchmail.org>; Tue, 11 Mar 2014 16:02:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id qIg0Oy0r-uBj for <notmuch@notmuchmail.org>;\r
+ Tue, 11 Mar 2014 16:02:40 -0700 (PDT)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id E3362429E26\r
+ for <notmuch@notmuchmail.org>; Tue, 11 Mar 2014 16:02:24 -0700 (PDT)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1WNVgm-0001vj-D3; Tue, 11 Mar 2014 20:02:24 -0300\r
+Received: (nullmailer pid 25859 invoked by uid 1000); Tue, 11 Mar 2014\r
+ 23:01:46 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v6 10/14] devel: add script to generate test databases\r
+Date: Tue, 11 Mar 2014 20:01:36 -0300\r
+Message-Id: <1394578900-25618-11-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.8.5.3\r
+In-Reply-To: <1394578900-25618-1-git-send-email-david@tethera.net>\r
+References: <1394578900-25618-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 11 Mar 2014 23:02:42 -0000\r
+\r
+From: Jani Nikula <jani@nikula.org>\r
+\r
+Add script to generate notmuch test databases using specified versions\r
+of notmuch. This is useful for generating material for database\r
+upgrade tests.\r
+\r
+This reuses the test infrastructure to have a sandbox environment for\r
+notmuch new etc.\r
+---\r
+ devel/gen-testdb.sh | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 131 insertions(+)\r
+ create mode 100755 devel/gen-testdb.sh\r
+\r
+diff --git a/devel/gen-testdb.sh b/devel/gen-testdb.sh\r
+new file mode 100755\r
+index 0000000..621b31e\r
+--- /dev/null\r
++++ b/devel/gen-testdb.sh\r
+@@ -0,0 +1,131 @@\r
++#!/usr/bin/env bash\r
++#\r
++# NAME\r
++# gen-testdb.sh - generate test databases\r
++#\r
++# SYNOPSIS\r
++# gen-testdb.sh -v NOTMUCH-VERSION [-c CORPUS-PATH] [-s TAR-SUFFIX]\r
++#\r
++# DESCRIPTION\r
++# Generate a tarball containing the specified test corpus and\r
++# the corresponding notmuch database, indexed using a specific\r
++# version of notmuch, resulting in a specific version of the\r
++# database.\r
++#\r
++# The specific version of notmuch will be built on the fly.\r
++# Therefore the script must be run within a git repository to be\r
++# able to build the old versions of notmuch.\r
++#\r
++# This script reuses the test infrastructure, and the script\r
++# must be run from within the test directory.\r
++#\r
++# The output tarballs, named database-<TAR-SUFFIX>.tar.gz, are\r
++# placed in the test/test-databases directory.\r
++#\r
++# OPTIONS\r
++# -v NOTMUCH-VERSION\r
++# Notmuch version in terms of a git tag or commit to use\r
++# for generating the database. Required.\r
++#\r
++# -c CORPUS-PATH\r
++# Path to a corpus to use for generating the\r
++# database. Due to CWD changes within the test\r
++# infrastructure, use absolute paths. Defaults to the\r
++# test corpus.\r
++#\r
++# -s TAR-SUFFIX\r
++# Suffix for the tarball basename. Empty by default.\r
++#\r
++# EXAMPLE\r
++#\r
++# Generate a database indexed with notmuch 0.17. Use the default\r
++# test corpus. Name the tarball database-v1.tar.gz to reflect\r
++# the fact that notmuch 0.17 used database version 1.\r
++#\r
++# $ cd test\r
++# $ ../devel/gen-testdb.sh -v 0.17 -s v1\r
++#\r
++# CAVEATS\r
++# Test infrastructure options won't work.\r
++#\r
++# Any existing databases with the same name will be overwritten.\r
++#\r
++# It may not be possible to build old versions of notmuch with\r
++# the set of dependencies that satisfy building the current\r
++# version of notmuch.\r
++#\r
++# AUTHOR\r
++# Jani Nikula <jani@nikula.org>\r
++#\r
++# LICENSE\r
++# Same as notmuch test infrastructure (GPLv2+).\r
++#\r
++\r
++test_description="database generation abusing test infrastructure"\r
++\r
++# immediate exit on subtest failure; see test_failure_ in test-lib.sh\r
++immediate=t\r
++\r
++VERSION=\r
++CORPUS=\r
++SUFFIX=\r
++\r
++while getopts v:c:s: opt; do\r
++ case "$opt" in\r
++ v) VERSION="$OPTARG";;\r
++ c) CORPUS="$OPTARG";;\r
++ s) SUFFIX="-$OPTARG";;\r
++ esac\r
++done\r
++shift `expr $OPTIND - 1`\r
++\r
++. ./test-lib.sh\r
++\r
++SHORT_CORPUS=$(basename ${CORPUS:-database})\r
++DBNAME=${SHORT_CORPUS}${SUFFIX}\r
++TARBALLNAME=${DBNAME}.tar.xz\r
++\r
++CORPUS=${CORPUS:-${TEST_DIRECTORY}/corpus}\r
++\r
++test_expect_code 0 "notmuch version specified on the command line" \\r
++ "test -n ${VERSION}"\r
++\r
++test_expect_code 0 "the specified version ${VERSION} refers to a commit" \\r
++ "git show ${VERSION} >/dev/null 2>&1"\r
++\r
++BUILD_DIR="notmuch-${VERSION}"\r
++test_expect_code 0 "generate snapshot of notmuch version ${VERSION}" \\r
++ "git -C $TEST_DIRECTORY/.. archive --prefix=${BUILD_DIR}/ --format=tar ${VERSION} | tar x"\r
++\r
++# force version string\r
++git describe --match '[0-9.]*' ${VERSION} > ${BUILD_DIR}/version\r
++\r
++test_expect_code 0 "configure and build notmuch version ${VERSION}" \\r
++ "make -C ${BUILD_DIR}"\r
++\r
++# use the newly built notmuch\r
++export PATH=./${BUILD_DIR}:$PATH\r
++\r
++test_begin_subtest "verify the newly built notmuch version"\r
++test_expect_equal "`notmuch --version`" "notmuch `cat ${BUILD_DIR}/version`"\r
++\r
++# replace the existing mails, if any, with the specified corpus\r
++rm -rf ${MAIL_DIR}\r
++cp -a ${CORPUS} ${MAIL_DIR}\r
++\r
++test_expect_code 0 "index the corpus" \\r
++ "notmuch new"\r
++\r
++# wrap the resulting mail store and database in a tarball\r
++\r
++cp -a ${MAIL_DIR} ${TMP_DIRECTORY}/${DBNAME}\r
++tar Jcf ${TMP_DIRECTORY}/${TARBALLNAME} -C ${TMP_DIRECTORY} ${DBNAME}\r
++mkdir -p ${TEST_DIRECTORY}/test-databases\r
++cp -a ${TMP_DIRECTORY}/${TARBALLNAME} ${TEST_DIRECTORY}/test-databases\r
++test_expect_code 0 "create the output tarball ${TARBALLNAME}" \\r
++ "test -f ${TEST_DIRECTORY}/test-databases/${TARBALLNAME}"\r
++\r
++# generate a checksum file\r
++test_expect_code 0 "compute checksum" \\r
++ "(cd ${TEST_DIRECTORY}/test-databases/ && sha256sum ${TARBALLNAME} > ${TARBALLNAME}.sha256)"\r
++test_done\r
+-- \r
+1.8.5.3\r
+\r