2010-12-01 21:27:52 +01:00
|
|
|
#!/usr/bin/env bash
|
2010-01-23 19:36:39 +01:00
|
|
|
|
2010-09-17 21:10:54 +02:00
|
|
|
# Run tests
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Junio C Hamano
|
2016-05-06 17:41:57 +02:00
|
|
|
# Copyright (c) 2010 Notmuch Developers
|
2010-09-17 21:10:54 +02:00
|
|
|
#
|
|
|
|
# Adapted from a Makefile to a shell script by Carl Worth (2010)
|
|
|
|
|
2010-10-28 21:07:42 +02:00
|
|
|
if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
|
|
|
|
echo "Error: The notmuch test suite requires a bash version >= 4.0"
|
|
|
|
echo "due to use of associative arrays within the test suite."
|
|
|
|
echo "Please try again with a newer bash (or help us fix the"
|
|
|
|
echo "test suite to be more portable). Thanks."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-09-25 22:38:27 +02:00
|
|
|
# Ensure NOTMUCH_SRCDIR and NOTMUCH_BUILDDIR are set.
|
|
|
|
. $(dirname "$0")/export-dirs.sh || exit 1
|
2010-09-17 21:10:54 +02:00
|
|
|
|
2021-05-17 10:11:09 +02:00
|
|
|
set -eu
|
|
|
|
|
2017-09-25 22:38:27 +02:00
|
|
|
TESTS=
|
2021-05-17 10:11:09 +02:00
|
|
|
for test in ${NOTMUCH_TESTS-}; do
|
2017-09-25 22:38:27 +02:00
|
|
|
TESTS="$TESTS $NOTMUCH_SRCDIR/test/$test"
|
|
|
|
done
|
|
|
|
|
2021-05-17 10:11:09 +02:00
|
|
|
if [ -z "$TESTS" ]; then
|
2017-09-25 22:38:27 +02:00
|
|
|
TESTS="$NOTMUCH_SRCDIR/test/T[0-9][0-9][0-9]-*.sh"
|
|
|
|
fi
|
2010-09-18 00:58:39 +02:00
|
|
|
|
2010-09-17 21:10:54 +02:00
|
|
|
# Clean up any results from a previous run
|
2017-09-25 22:38:27 +02:00
|
|
|
rm -rf $NOTMUCH_BUILDDIR/test/test-results
|
2010-09-17 21:10:54 +02:00
|
|
|
|
2016-06-09 21:20:56 +02:00
|
|
|
# Test for timeout utility
|
2011-05-28 11:50:11 +02:00
|
|
|
if command -v timeout >/dev/null; then
|
2019-05-20 19:20:56 +02:00
|
|
|
TEST_TIMEOUT=${NOTMUCH_TEST_TIMEOUT:-2m}
|
2019-05-21 01:25:35 +02:00
|
|
|
if [ "$TEST_TIMEOUT" = 0 ]; then
|
|
|
|
TEST_TIMEOUT_CMD=""
|
|
|
|
echo "INFO: timeout disabled"
|
|
|
|
else
|
|
|
|
TEST_TIMEOUT_CMD="timeout $TEST_TIMEOUT"
|
|
|
|
echo "INFO: using $TEST_TIMEOUT timeout for tests"
|
|
|
|
fi
|
2011-05-28 11:50:11 +02:00
|
|
|
else
|
|
|
|
TEST_TIMEOUT_CMD=""
|
|
|
|
fi
|
|
|
|
|
2019-05-26 17:03:13 +02:00
|
|
|
META_FAILURE=
|
2021-05-17 10:11:09 +02:00
|
|
|
RES=0
|
2010-09-17 21:10:54 +02:00
|
|
|
# Run the tests
|
2021-05-17 10:11:09 +02:00
|
|
|
if test -z "${NOTMUCH_TEST_SERIALIZE-}" && command -v parallel >/dev/null ; then
|
2019-05-08 20:51:47 +02:00
|
|
|
test -t 1 && export COLORS_WITHOUT_TTY=t || :
|
2021-08-02 13:21:42 +02:00
|
|
|
if parallel --minversion 0 >/dev/null 2>&1 ; then
|
2019-05-04 22:57:43 +02:00
|
|
|
echo "INFO: running tests with GNU parallel"
|
2021-05-17 10:11:09 +02:00
|
|
|
printf '%s\n' $TESTS | $TEST_TIMEOUT_CMD parallel || RES=$?
|
2019-05-04 22:57:43 +02:00
|
|
|
else
|
|
|
|
echo "INFO: running tests with moreutils parallel"
|
2021-05-17 10:11:09 +02:00
|
|
|
$TEST_TIMEOUT_CMD parallel -- $TESTS || RES=$?
|
2012-11-28 05:13:16 +01:00
|
|
|
fi
|
2021-05-17 10:11:09 +02:00
|
|
|
if [ $RES != 0 ]; then
|
2019-05-26 17:03:13 +02:00
|
|
|
META_FAILURE="parallel test suite returned error code $RES"
|
2019-05-20 19:20:57 +02:00
|
|
|
fi
|
2019-05-04 22:57:43 +02:00
|
|
|
else
|
2021-05-17 10:11:09 +02:00
|
|
|
trap 'e=$?; trap - 0; kill ${!-}; exit $e' 0 HUP INT TERM
|
2019-05-04 22:57:43 +02:00
|
|
|
for test in $TESTS; do
|
|
|
|
$TEST_TIMEOUT_CMD $test "$@" &
|
2021-05-17 10:11:09 +02:00
|
|
|
wait $! && ev=0 || ev=$?
|
|
|
|
test $ev = 0 || RES=$ev
|
2019-05-04 22:57:43 +02:00
|
|
|
done
|
2021-05-17 10:11:09 +02:00
|
|
|
trap - 0 HUP INT TERM
|
|
|
|
if [ $RES != 0 ]; then
|
|
|
|
META_FAILURE="some tests failed; first failed returned error code $RES"
|
|
|
|
fi
|
2019-05-04 22:57:43 +02:00
|
|
|
fi
|
2010-09-17 21:10:54 +02:00
|
|
|
|
|
|
|
# Report results
|
2021-05-17 10:11:09 +02:00
|
|
|
RESULT_FILES=
|
|
|
|
for file in $TESTS
|
|
|
|
do
|
|
|
|
file=${file##*/} # drop leading path components
|
|
|
|
file=${file%.sh} # drop trailing '.sh'
|
|
|
|
RESULT_FILES="$RESULT_FILES $NOTMUCH_BUILDDIR/test/test-results/$file"
|
|
|
|
done
|
|
|
|
|
2013-11-25 18:08:18 +01:00
|
|
|
echo
|
2021-05-17 10:11:09 +02:00
|
|
|
$NOTMUCH_SRCDIR/test/aggregate-results.sh $RESULT_FILES && ev=0 || ev=$?
|
|
|
|
|
2019-05-26 17:03:13 +02:00
|
|
|
if [ -n "$META_FAILURE" ]; then
|
|
|
|
printf 'ERROR: %s\n' "$META_FAILURE"
|
|
|
|
if [ $ev = 0 ]; then
|
|
|
|
ev=$RES
|
|
|
|
fi
|
|
|
|
fi
|
2010-09-17 21:10:54 +02:00
|
|
|
|
|
|
|
# Clean up
|
2019-05-04 22:57:43 +02:00
|
|
|
rm -rf $NOTMUCH_BUILDDIR/test/test-results
|
2013-09-08 17:53:30 +02:00
|
|
|
|
|
|
|
exit $ev
|