2 # Copyright (c) 2005 Junio C Hamano
3 # Copyright (c) 2010 Notmuch Developers
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see https://www.gnu.org/licenses/ .
18 # This file contains common code to be used by both the regular
19 # (correctness) tests and the performance tests.
21 # test-lib.sh defines die() which echoes to nonstandard fd where
22 # output was redirected earlier in that file. If test-lib.sh is not
23 # loaded, neither this redirection nor die() function were defined.
25 type die >/dev/null 2>&1 || die () { echo "$@" >&2; exit 1; }
31 while [ -n "$dir" ]; do
33 if [ -x "$bin" ]; then
37 dir="$(dirname "$dir")"
38 if [ "$dir" = "/" ]; then
45 test_name=$(basename $0 .sh)
46 rm -rf notmuch-dir-backup."$test_name"
47 cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup."${test_name}"
51 test_name=$(basename $0 .sh)
52 rm -rf ${MAIL_DIR}/.notmuch
53 cp -pR notmuch-dir-backup."${test_name}" ${MAIL_DIR}/.notmuch
56 # Test the binaries we have just built. The tests are kept in
57 # test/ subdirectory and are run in 'trash directory' subdirectory.
58 TEST_DIRECTORY=$(pwd -P)
59 notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"`
61 # Prepend $TEST_DIRECTORY/../lib to LD_LIBRARY_PATH, to make tests work
62 # on systems where ../notmuch depends on LD_LIBRARY_PATH.
63 LD_LIBRARY_PATH=${TEST_DIRECTORY%/*}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
64 export LD_LIBRARY_PATH
67 . $notmuch_path/sh.config || exit 1
69 if test -n "$valgrind"
73 test "$1" = "$(readlink "$2")" || {
81 while test -d "$2".lock
83 say "Waiting for lock on $2."
90 make_valgrind_symlink () {
91 # handle only executables
92 test -x "$1" || return
95 symlink_target=$TEST_DIRECTORY/../$base
96 # do not override scripts
97 if test -x "$symlink_target" &&
98 test ! -d "$symlink_target" &&
99 test "#!" != "$(head -c 2 < "$symlink_target")"
101 symlink_target=$TEST_DIRECTORY/valgrind.sh
105 symlink_target=$TEST_DIRECTORY/unprocessed-script
107 # create the link, or replace it if it is out of date
108 make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
111 # override notmuch executable in TEST_DIRECTORY/..
112 GIT_VALGRIND=$TEST_DIRECTORY/valgrind
113 mkdir -p "$GIT_VALGRIND"/bin
114 make_valgrind_symlink $TEST_DIRECTORY/../notmuch
119 ls "$path"/notmuch 2> /dev/null |
122 make_valgrind_symlink "$file"
126 PATH=$GIT_VALGRIND/bin:$PATH
127 GIT_EXEC_PATH=$GIT_VALGRIND/bin
129 test -n "$notmuch_path" && MANPATH="$notmuch_path/doc/_build/man"
131 if test -n "$notmuch_path"
133 PATH="$notmuch_path:$PATH"
134 MANPATH="$notmuch_path/doc/_build/man"
140 test="tmp.$(basename "$0" .sh)"
141 test -n "$root" && test="$root/$test"
143 /*) TMP_DIRECTORY="$test" ;;
144 *) TMP_DIRECTORY="$TEST_DIRECTORY/$test" ;;
146 test ! -z "$debug" || remove_tmp=$TMP_DIRECTORY
149 echo >&6 "FATAL: Cannot prepare test area"
153 # A temporary home directory is needed by at least:
154 # - emacs/"Sending a message via (fake) SMTP"
155 # - emacs/"Reply within emacs"
156 # - crypto/emacs_deliver_message
157 export HOME="${TMP_DIRECTORY}/home"
160 MAIL_DIR="${TMP_DIRECTORY}/mail"
161 export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
164 mkdir -p "${MAIL_DIR}"
166 cat <<EOF >"${NOTMUCH_CONFIG}"
171 name=Notmuch Test Suite
172 primary_email=test_suite@notmuchmail.org
173 other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org