1#!/bin/sh
2
3trap 'rm $test.valgrind-errors; exit 1' INT QUIT
4
5total=0
6pass=0
7clean=0
8
9echo "====== Testing for correctness ======"
10for test in *.c; do
11    echo -n "Testing $test..."
12    ../glcpp < $test > $test.out 2>&1
13    total=$((total+1))
14    if cmp $test.expected $test.out >/dev/null 2>&1; then
15	echo "PASS"
16	pass=$((pass+1))
17    else
18	echo "FAIL"
19	diff -u $test.expected $test.out
20    fi
21done
22
23echo ""
24echo "$pass/$total tests returned correct results"
25echo ""
26
27echo "====== Testing for valgrind cleanliness ======"
28for test in *.c; do
29    echo -n "Testing $test with valgrind..."
30    valgrind --error-exitcode=31 --log-file=$test.valgrind-errors ../glcpp < $test >/dev/null 2>&1
31    if [ "$?" = "31" ]; then
32	echo "ERRORS"
33	cat $test.valgrind-errors
34    else
35	echo "CLEAN"
36	clean=$((clean+1))
37	rm $test.valgrind-errors
38    fi
39done
40
41echo ""
42echo "$pass/$total tests returned correct results"
43echo "$clean/$total tests are valgrind-clean"
44
45if [ "$pass" = "$total" ] && [ "$clean" = "$total" ]; then
46    exit 0
47else
48    exit 1
49fi
50
51