5 # Copyright (c) 2005 Junio C Hamano
6 # Copyright (c) 2010 Notmuch Developers
8 # Adapted from a Makefile to a shell script by Carl Worth (2010)
10 if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
11 echo "Error: The notmuch test suite requires a bash version >= 4.0"
12 echo "due to use of associative arrays within the test suite."
13 echo "Please try again with a newer bash (or help us fix the"
14 echo "test suite to be more portable). Thanks."
18 # Ensure NOTMUCH_SRCDIR and NOTMUCH_BUILDDIR are set.
19 . $(dirname "$0")/export-dirs.sh || exit 1
24 for test in ${NOTMUCH_TESTS-}; do
25 TESTS="$TESTS $NOTMUCH_SRCDIR/test/$test"
28 if [ -z "$TESTS" ]; then
29 TESTS="$NOTMUCH_SRCDIR/test/T[0-9][0-9][0-9]-*.sh"
32 # Clean up any results from a previous run
33 rm -rf $NOTMUCH_BUILDDIR/test/test-results
35 # Test for timeout utility
36 if command -v timeout >/dev/null; then
37 TEST_TIMEOUT=${NOTMUCH_TEST_TIMEOUT:-2m}
38 if [ "$TEST_TIMEOUT" = 0 ]; then
40 echo "INFO: timeout disabled"
42 TEST_TIMEOUT_CMD="timeout $TEST_TIMEOUT"
43 echo "INFO: using $TEST_TIMEOUT timeout for tests"
52 if test -z "${NOTMUCH_TEST_SERIALIZE-}" && command -v parallel >/dev/null ; then
53 test -t 1 && export COLORS_WITHOUT_TTY=t || :
54 if parallel --minversion 0 >/dev/null 2>&1 ; then
55 echo "INFO: running tests with GNU parallel"
56 printf '%s\n' $TESTS | $TEST_TIMEOUT_CMD parallel || RES=$?
58 echo "INFO: running tests with moreutils parallel"
59 $TEST_TIMEOUT_CMD parallel -- $TESTS || RES=$?
61 if [ $RES != 0 ]; then
62 META_FAILURE="parallel test suite returned error code $RES"
65 trap 'e=$?; trap - 0; kill ${!-}; exit $e' 0 HUP INT TERM
66 for test in $TESTS; do
67 $TEST_TIMEOUT_CMD $test "$@" &
68 wait $! && ev=0 || ev=$?
69 test $ev = 0 || RES=$ev
72 if [ $RES != 0 ]; then
73 META_FAILURE="some tests failed; first failed returned error code $RES"
81 file=${file##*/} # drop leading path components
82 file=${file%.sh} # drop trailing '.sh'
83 RESULT_FILES="$RESULT_FILES $NOTMUCH_BUILDDIR/test/test-results/$file"
87 $NOTMUCH_SRCDIR/test/aggregate-results.sh $RESULT_FILES && ev=0 || ev=$?
89 if [ -n "$META_FAILURE" ]; then
90 printf 'ERROR: %s\n' "$META_FAILURE"
97 rm -rf $NOTMUCH_BUILDDIR/test/test-results