| 1 | #!/bin/bash |
| 2 | |
| 3 | bad= |
| 4 | |
| 5 | if [ "$NO_VALGRIND" ]; then |
| 6 | cmd=(./testsuite) |
| 7 | else |
| 8 | cmd=(valgrind --error-exitcode=1 --leak-check=full ./testsuite) |
| 9 | fi |
| 10 | |
| 11 | set -o pipefail |
| 12 | # Stdout goes directly to testsuite.out; stderr goes down the pipe. |
| 13 | if ! "${cmd[@]}" 2>&1 >testsuite.out | tee testsuite.err; then |
| 14 | echo >&2 'Memory errors!' |
| 15 | bad=1 |
| 16 | fi |
| 17 | |
| 18 | if grep 'LEAK SUMMARY' testsuite.err >/dev/null; then |
| 19 | echo >&2 'Memory leaks!' |
| 20 | bad=1 |
| 21 | fi |
| 22 | |
| 23 | if ! diff -u testsuite.expected testsuite.out; then |
| 24 | echo >&2 'Output is incorrect!' |
| 25 | bad=1 |
| 26 | fi |
| 27 | |
| 28 | if [ $bad ]; then |
| 29 | echo >&2 'Test suite failed!' |
| 30 | exit 1 |
| 31 | else |
| 32 | echo 'Test suite passed.' |
| 33 | fi |