]> git.notmuchmail.org Git - notmuch/blob - devel/gen-testdb.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / devel / gen-testdb.sh
1 #!/usr/bin/env bash
2 #
3 # NAME
4 #       gen-testdb.sh - generate test databases
5 #
6 # SYNOPSIS
7 #       gen-testdb.sh -v NOTMUCH-VERSION [-c CORPUS-PATH] [-s TAR-SUFFIX]
8 #
9 # DESCRIPTION
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
13 #       database.
14 #
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.
18 #
19 #       This script reuses the test infrastructure, and the script
20 #       must be run from within the test directory.
21 #
22 #       The output tarballs, named database-<TAR-SUFFIX>.tar.gz, are
23 #       placed in the test/test-databases directory.
24 #
25 # OPTIONS
26 #       -v NOTMUCH-VERSION
27 #               Notmuch version in terms of a git tag or commit to use
28 #               for generating the database. Required.
29 #
30 #       -c CORPUS-PATH
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
34 #               test corpus.
35 #
36 #       -s TAR-SUFFIX
37 #               Suffix for the tarball basename. Empty by default.
38 #
39 # EXAMPLE
40 #
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.
44 #
45 #       $ cd test
46 #       $ ../devel/gen-testdb.sh -v 0.17 -s v1
47 #
48 # CAVEATS
49 #       Test infrastructure options won't work.
50 #
51 #       Any existing databases with the same name will be overwritten.
52 #
53 #       It may not be possible to build old versions of notmuch with
54 #       the set of dependencies that satisfy building the current
55 #       version of notmuch.
56 #
57 # AUTHOR
58 #       Jani Nikula <jani@nikula.org>
59 #
60 # LICENSE
61 #       Same as notmuch test infrastructure (GPLv2+).
62 #
63
64 test_description="database generation abusing test infrastructure"
65
66 # immediate exit on subtest failure; see test_failure_ in test-lib.sh
67 immediate=t
68
69 VERSION=
70 CORPUS=
71 SUFFIX=
72
73 while getopts v:c:s: opt; do
74     case "$opt" in
75         v) VERSION="$OPTARG";;
76         c) CORPUS="$OPTARG";;
77         s) SUFFIX="-$OPTARG";;
78     esac
79 done
80 shift `expr $OPTIND - 1`
81
82 . ./test-lib.sh || exit 1
83
84 SHORT_CORPUS=$(basename ${CORPUS:-database})
85 DBNAME=${SHORT_CORPUS}${SUFFIX}
86 TARBALLNAME=${DBNAME}.tar.xz
87
88 CORPUS=${CORPUS:-${TEST_DIRECTORY}/corpus}
89
90 test_expect_code 0 "notmuch version specified on the command line" \
91     "test -n ${VERSION}"
92
93 test_expect_code 0 "the specified version ${VERSION} refers to a commit" \
94     "git show ${VERSION} >/dev/null 2>&1"
95
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"
99
100 # force version string
101 git describe --match '[0-9.]*' ${VERSION} > ${BUILD_DIR}/version
102
103 test_expect_code 0 "configure and build notmuch version ${VERSION}" \
104     "make -C ${BUILD_DIR}"
105
106 # use the newly built notmuch
107 export PATH=./${BUILD_DIR}:$PATH
108
109 test_begin_subtest "verify the newly built notmuch version"
110 test_expect_equal "`notmuch --version`" "notmuch `cat ${BUILD_DIR}/version`"
111
112 # replace the existing mails, if any, with the specified corpus
113 rm -rf ${MAIL_DIR}
114 cp -a ${CORPUS} ${MAIL_DIR}
115
116 test_expect_code 0 "index the corpus" \
117     "notmuch new"
118
119 # wrap the resulting mail store and database in a tarball
120
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}"
127
128 # generate a checksum file
129 test_expect_code 0 "compute checksum" \
130     "(cd ${TEST_DIRECTORY}/test-databases/ && sha256sum ${TARBALLNAME} > ${TARBALLNAME}.sha256)"
131 test_done