]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test
b8437127c01fccc98c6f9be595f6cd1b8b0ebb5c
[notmuch] / test / notmuch-test
1 #!/usr/bin/env bash
2
3 # Run tests
4 #
5 # Copyright (c) 2005 Junio C Hamano
6 #
7 # Adapted from a Makefile to a shell script by Carl Worth (2010)
8
9 if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
10     echo "Error: The notmuch test suite requires a bash version >= 4.0"
11     echo "due to use of associative arrays within the test suite."
12     echo "Please try again with a newer bash (or help us fix the"
13     echo "test suite to be more portable). Thanks."
14     exit 1
15 fi
16
17 cd $(dirname "$0")
18
19 TESTS=${NOTMUCH_TESTS:-`echo T[0-9][0-9][0-9]-*.sh`}
20
21 # Clean up any results from a previous run
22 rm -r test-results >/dev/null 2>/dev/null
23
24 # test for timeout utility
25 if command -v timeout >/dev/null; then
26     TEST_TIMEOUT_CMD="timeout 2m "
27     echo "INFO: using 2 minute timeout for tests"
28 else
29     TEST_TIMEOUT_CMD=""
30 fi
31
32 trap 'e=$?; kill $!; exit $e' HUP INT TERM
33 # Run the tests
34 for test in $TESTS; do
35     $TEST_TIMEOUT_CMD ./$test "$@" &
36     wait $!
37     # If the test failed without producing results, then it aborted,
38     # so we should abort, too.
39     RES=$?
40     if [[ $RES != 0 && ! -e "test-results/${test%.sh}" ]]; then
41         exit $RES
42     fi
43 done
44 trap - HUP INT TERM
45
46 # Report results
47 echo
48 ./aggregate-results.sh test-results/*
49 ev=$?
50
51 # Clean up
52 rm -rf test-results corpus.mail
53
54 exit $ev