#!/bin/sh

if [ "$1" = "-val" ]
then
    shift
    [ ! -d .valgrind ] && mkdir .valgrind
    rm -f .valgrind/log*
    PROG=./run_vallog
elif [ "$1" = "-tdns" ]
then
    shift
    PROG=./run_tdns
else
    PROG=../bin/spfquery/spfquery_static
fi

echo
echo "Doing regression tests as one large batch...."
echo "Prog = $PROG"

(perl test.pl -impl libspf-alt -program $PROG -data test.txt -pipe-out | \
 perl test.pl -impl libspf-alt -program $PROG -data test.txt -pipe-in ) 2>&1 \
	    | grep -v "^ok [0-9][0-9]*" | tee tests_many.out

num_errors=`grep "^# Test [0-9][0-9]* got:" tests_many.out | grep -v "\*TODO\*)" | wc -l`
num_errors=`expr $num_errors + 0`

if [ $num_errors -ne 0 ]
then
    echo "Error:  $num_errors tests failed"
else
    echo "All regression tests passed"
fi

if [ "$1" = "-val" ]
then
    grep -n "== ERROR SUMMARY: " .valgrind/log* | grep -v "0 errors from 0 contexts" | head
fi

[ $num_errors -ne 0 ] && exit 1

exit 0


syntax highlighted by Code2HTML, v. 0.9.1