Import upstream sources.
[cparse] / tests.bash
1 #! /bin/bash
2 set -e
3
4 failed() {
5 echo FAILED
6 status=1
7 cat $errors
8 echo
9 }
10
11 case "$TEST_COMPILER" in
12 "" )
13 validate() {
14 ./cparse -- "$@"
15 }
16 ;;
17 * )
18 validate() {
19 $TEST_COMPILER -c "$@"
20 }
21 ;;
22 esac
23
24 if test $# = 0; then
25 set -- tests/*.c
26 fi
27
28 mkdir -p errors
29 rm -f errors/*
30 status=0
31
32 for test; do
33 printf "*** $test: "
34 errors=${test//tests/errors}
35 case $test in
36 tests/fail-* )
37 if validate $test 2> $errors > /dev/null; then
38 echo UNEXPECTEDLY SUCCEEDED
39 status=1
40 else
41 echo OK
42 fi
43 ;;
44 * )
45 if validate $test 2> $errors > /dev/null; then
46 echo OK
47 else
48 failed
49 fi
50 ;;
51 esac
52 done
53
54 # make sure we can parse ourselves, and that if we do it twice we
55 # get the same answer both times
56 #
57 # really we should compile the results and check they match what
58 # the compiler produces without our involvement
59
60 for path in *.c; do
61 printf "*** $path: "
62 errors=errors/${path}.errors
63 once=errors/${path%.c}.i
64 twice=errors/${path%.c}.j
65 object=errors/${path%.c}.o
66 rm -f ${once} ${twice} ${errors}
67 echo ./cparse --cpp ${CC} ${ALL_CFLAGS} -- ${path} > ${once} > $errors
68 if ! ./cparse --cpp ${CC} ${ALL_CFLAGS} -- ${path} > ${once} 2>> $errors; then
69 failed
70 elif ! ./cparse --no-cpp -- ${once} > ${twice} 2> $errors; then
71 failed
72 elif ! diff -u ${once} ${twice} > $errors 2>&1; then
73 failed
74 elif ! ${CC} ${ALL_CFLAGS} -o ${object} -c ${once} 2> $errors; then
75 failed
76 else
77 echo OK
78 fi
79 done
80
81 exit $status