#!/bin/sh
#
# run_tests - Run the tests for "treecc".
#
# Copyright (C) 2001  Southern Storm Software, Pty Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

TMPFILE=/tmp/test$$
TMPFILEB=/tmp/test2$$
TMPFILEC=/tmp/test3$$

trap 'rm -f $TMPFILE $TMPFILEB $TMPFILEC' 1 2 15

process()
{
	echo -n "$1 $2.tst: "
	if ./$1 "$srcdir/$2.tst" | ./normalize >$TMPFILE ; then
		cat "$srcdir/$2.out" | ./normalize >$TMPFILEC
		if diff $TMPFILEC $TMPFILE >$TMPFILEB ; then
			echo "ok"
			return 0
		else
			echo "failed"
			cat $TMPFILEB
			return 1
		fi
	else
		echo "failed with exit status non-zero"
		return 1
	fi
}

STATUS=0
while read LINE; do
	if process $LINE ; then
		:
	else
		STATUS=1
	fi
done <"$srcdir/test_list"

rm -f $TMPFILE $TMPFILEB $TMPFILEC
exit $STATUS
