4 # gen-testdb.sh - generate test databases
7 # gen-testdb.sh -v NOTMUCH-VERSION [-c CORPUS-PATH] [-s TAR-SUFFIX]
10 # Generate a tarball containing the specified test corpus and
11 # the corresponding notmuch database, indexed using a specific
12 # version of notmuch, resulting in a specific version of the
15 # The specific version of notmuch will be built on the fly.
16 # Therefore the script must be run within a git repository to be
17 # able to build the old versions of notmuch.
19 # This script reuses the test infrastructure, and the script
20 # must be run from within the test directory.
22 # The output tarballs, named database-<TAR-SUFFIX>.tar.gz, are
23 # placed in the test/test-databases directory.
27 # Notmuch version in terms of a git tag or commit to use
28 # for generating the database. Required.
31 # Path to a corpus to use for generating the
32 # database. Due to CWD changes within the test
33 # infrastructure, use absolute paths. Defaults to the
37 # Suffix for the tarball basename. Empty by default.
41 # Generate a database indexed with notmuch 0.17. Use the default
42 # test corpus. Name the tarball database-v1.tar.gz to reflect
43 # the fact that notmuch 0.17 used database version 1.
46 # $ ../devel/gen-testdb.sh -v 0.17 -s v1
49 # Test infrastructure options won't work.
51 # Any existing databases with the same name will be overwritten.
53 # It may not be possible to build old versions of notmuch with
54 # the set of dependencies that satisfy building the current
58 # Jani Nikula <jani@nikula.org>
61 # Same as notmuch test infrastructure (GPLv2+).
64 test_description="database generation abusing test infrastructure"
66 # immediate exit on subtest failure; see test_failure_ in test-lib.sh
73 while getopts v:c:s: opt; do
75 v) VERSION="$OPTARG";;
77 s) SUFFIX="-$OPTARG";;
80 shift `expr $OPTIND - 1`
82 . ./test-lib.sh || exit 1
84 SHORT_CORPUS=$(basename ${CORPUS:-database})
85 DBNAME=${SHORT_CORPUS}${SUFFIX}
86 TARBALLNAME=${DBNAME}.tar.xz
88 CORPUS=${CORPUS:-${TEST_DIRECTORY}/corpus}
90 test_expect_code 0 "notmuch version specified on the command line" \
93 test_expect_code 0 "the specified version ${VERSION} refers to a commit" \
94 "git show ${VERSION} >/dev/null 2>&1"
96 BUILD_DIR="notmuch-${VERSION}"
97 test_expect_code 0 "generate snapshot of notmuch version ${VERSION}" \
98 "git -C $TEST_DIRECTORY/.. archive --prefix=${BUILD_DIR}/ --format=tar ${VERSION} | tar x"
100 # force version string
101 git describe --match '[0-9.]*' ${VERSION} > ${BUILD_DIR}/version
103 test_expect_code 0 "configure and build notmuch version ${VERSION}" \
104 "make -C ${BUILD_DIR}"
106 # use the newly built notmuch
107 export PATH=./${BUILD_DIR}:$PATH
109 test_begin_subtest "verify the newly built notmuch version"
110 test_expect_equal "`notmuch --version`" "notmuch `cat ${BUILD_DIR}/version`"
112 # replace the existing mails, if any, with the specified corpus
114 cp -a ${CORPUS} ${MAIL_DIR}
116 test_expect_code 0 "index the corpus" \
119 # wrap the resulting mail store and database in a tarball
121 cp -a ${MAIL_DIR} ${TMP_DIRECTORY}/${DBNAME}
122 tar Jcf ${TMP_DIRECTORY}/${TARBALLNAME} -C ${TMP_DIRECTORY} ${DBNAME}
123 mkdir -p ${TEST_DIRECTORY}/test-databases
124 cp -a ${TMP_DIRECTORY}/${TARBALLNAME} ${TEST_DIRECTORY}/test-databases
125 test_expect_code 0 "create the output tarball ${TARBALLNAME}" \
126 "test -f ${TEST_DIRECTORY}/test-databases/${TARBALLNAME}"
128 # generate a checksum file
129 test_expect_code 0 "compute checksum" \
130 "(cd ${TEST_DIRECTORY}/test-databases/ && sha256sum ${TARBALLNAME} > ${TARBALLNAME}.sha256)"