]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test
notmuch (0.27-2) unstable; urgency=medium
[notmuch] / test / notmuch-test
1 #!/usr/bin/env bash
2
3 # Run tests
4 #
5 # Copyright (c) 2005 Junio C Hamano
6 # Copyright (c) 2010 Notmuch Developers
7 #
8 # Adapted from a Makefile to a shell script by Carl Worth (2010)
9
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."
15     exit 1
16 fi
17
18 # Ensure NOTMUCH_SRCDIR and NOTMUCH_BUILDDIR are set.
19 . $(dirname "$0")/export-dirs.sh || exit 1
20
21 TESTS=
22 for test in $NOTMUCH_TESTS; do
23     TESTS="$TESTS $NOTMUCH_SRCDIR/test/$test"
24 done
25
26 if [[ -z "$TESTS" ]]; then
27     TESTS="$NOTMUCH_SRCDIR/test/T[0-9][0-9][0-9]-*.sh"
28 fi
29
30 # Clean up any results from a previous run
31 rm -rf $NOTMUCH_BUILDDIR/test/test-results
32
33 # Test for timeout utility
34 if command -v timeout >/dev/null; then
35     TEST_TIMEOUT_CMD="timeout 2m"
36     echo "INFO: using 2 minute timeout for tests"
37 else
38     TEST_TIMEOUT_CMD=""
39 fi
40
41 trap 'e=$?; kill $!; exit $e' HUP INT TERM
42 # Run the tests
43 for test in $TESTS; do
44     $TEST_TIMEOUT_CMD $test "$@" &
45     wait $!
46     # If the test failed without producing results, then it aborted,
47     # so we should abort, too.
48     RES=$?
49     testname=$(basename $test .sh)
50     if [[ $RES != 0 && ! -e "$NOTMUCH_BUILDDIR/test/test-results/$testname" ]]; then
51         exit $RES
52     fi
53 done
54 trap - HUP INT TERM
55
56 # Report results
57 echo
58 $NOTMUCH_SRCDIR/test/aggregate-results.sh $NOTMUCH_BUILDDIR/test/test-results/*
59 ev=$?
60
61 # Clean up
62 rm -rf $NOTMUCH_BUILDDIR/test/test-results $NOTMUCH_BUILDDIR/test/corpora.mail
63
64 exit $ev