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
70 if [ -e ./test-lib-$PLATFORM.sh ]; then
71 . ./test-lib-$PLATFORM.sh || exit 1
74 if test -n "$valgrind"
78 test "$1" = "$(readlink "$2")" || {
86 while test -d "$2".lock
88 say "Waiting for lock on $2."
95 make_valgrind_symlink () {
96 # handle only executables
97 test -x "$1" || return
100 symlink_target=$TEST_DIRECTORY/../$base
101 # do not override scripts
102 if test -x "$symlink_target" &&
103 test ! -d "$symlink_target" &&
104 test "#!" != "$(head -c 2 < "$symlink_target")"
106 symlink_target=$TEST_DIRECTORY/valgrind.sh
110 symlink_target=$TEST_DIRECTORY/unprocessed-script
112 # create the link, or replace it if it is out of date
113 make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
116 # override notmuch executable in TEST_DIRECTORY/..
117 GIT_VALGRIND=$TEST_DIRECTORY/valgrind
118 mkdir -p "$GIT_VALGRIND"/bin
119 make_valgrind_symlink $TEST_DIRECTORY/../notmuch
124 ls "$path"/notmuch 2> /dev/null |
127 make_valgrind_symlink "$file"
131 PATH=$GIT_VALGRIND/bin:$PATH
132 GIT_EXEC_PATH=$GIT_VALGRIND/bin
134 test -n "$notmuch_path" && MANPATH="$notmuch_path/doc/_build/man"
136 if test -n "$notmuch_path"
138 PATH="$notmuch_path:$PATH"
139 MANPATH="$notmuch_path/doc/_build/man"
145 test="tmp.$(basename "$0" .sh)"
146 test -n "$root" && test="$root/$test"
148 /*) TMP_DIRECTORY="$test" ;;
149 *) TMP_DIRECTORY="$TEST_DIRECTORY/$test" ;;
151 test ! -z "$debug" || remove_tmp=$TMP_DIRECTORY
154 echo >&6 "FATAL: Cannot prepare test area"
158 # A temporary home directory is needed by at least:
159 # - emacs/"Sending a message via (fake) SMTP"
160 # - emacs/"Reply within emacs"
161 # - crypto/emacs_deliver_message
162 export HOME="${TMP_DIRECTORY}/home"
165 MAIL_DIR="${TMP_DIRECTORY}/mail"
166 export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
169 mkdir -p "${MAIL_DIR}"
171 cat <<EOF >"${NOTMUCH_CONFIG}"
176 name=Notmuch Test Suite
177 primary_email=test_suite@notmuchmail.org
178 other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org