#!/bin/bash

if [ ! -e kite ]; then
	echo "Please build Kite first.";
	exit -1;
fi

NUM_PASS=0;
NUM_FAIL=0;

rm -f test.log

# Staged install into temp folder for testing.
LOC=`pwd`
mkdir $LOC/tmp
make prefix=$LOC/tmp install

rm -f $LOC/test.log
cd $LOC/tmp/lib/kite
for i in `find $LOC/tests -name '[A-Za-z]*.kt' | grep -v '.svn'`; do
	echo -n "$i: "
	echo "$i:" >>$LOC/test.log
	$LOC/kite < $i 2>&1 | diff -a - $i.out >>$LOC/test.log 2>&1
	if [ "$?" -ne 0 ]; then
		NUM_FAIL=$(($NUM_FAIL + 1));
		echo "FAIL"
	else
		NUM_PASS=$(($NUM_PASS + 1));
		echo "pass"
	fi;
	echo >>$LOC/test.log
done

echo "All tests run."
echo $NUM_PASS "test(s) passed," $NUM_FAIL "test(s) failed."

cd $LOC
rm -rf $LOC/tmp

exit $NUM_FAIL;
