#! /bin/bash set -e failed() { echo FAILED status=1 cat $errors echo } case "$TEST_COMPILER" in "" ) validate() { ./cparse -- "$@" } ;; * ) validate() { $TEST_COMPILER -c "$@" } ;; esac if test $# = 0; then set -- tests/*.c fi mkdir -p errors rm -f errors/* status=0 for test; do printf "*** $test: " errors=${test//tests/errors} case $test in tests/fail-* ) if validate $test 2> $errors > /dev/null; then echo UNEXPECTEDLY SUCCEEDED status=1 else echo OK fi ;; * ) if validate $test 2> $errors > /dev/null; then echo OK else failed fi ;; esac done # make sure we can parse ourselves, and that if we do it twice we # get the same answer both times # # really we should compile the results and check they match what # the compiler produces without our involvement for path in *.c; do printf "*** $path: " errors=errors/${path}.errors once=errors/${path%.c}.i twice=errors/${path%.c}.j object=errors/${path%.c}.o rm -f ${once} ${twice} ${errors} echo ./cparse --cpp ${CC} ${ALL_CFLAGS} -- ${path} > ${once} > $errors if ! ./cparse --cpp ${CC} ${ALL_CFLAGS} -- ${path} > ${once} 2>> $errors; then failed elif ! ./cparse --no-cpp -- ${once} > ${twice} 2> $errors; then failed elif ! diff -u ${once} ${twice} > $errors 2>&1; then failed elif ! ${CC} ${ALL_CFLAGS} -o ${object} -c ${once} 2> $errors; then failed else echo OK fi done exit $status