#!/bin/csh -f
#
# Test program for Wild-LIFE
#
#	test *.lf
#   or
#	test program
#
# This program run Wild-LIFE over one or several test programs and records the
# differences in the standard and error outputs.
#
#
# Read-only files:
#	program.lf	Life source code
#	program.in	Life user input
#	program.ref	Reference standard output
#	program.referr	Reference error output
#
# Output files:
#	program.out	Most recent standard output
#	program.err	Most recent error output
#	program.refdiff Difference between .out and .ref files
#	program.errdiff Difference between .err and .referr files
#


# Make all files rw by everyone
umask 000


# Version of Wild-LIFE to use:
set WLIFE = "../Source/wild_life"


# clear
echo "Testing interpreter: $WLIFE"
echo "Date: `date`"
echo ""
# echo ""
# echo "                       Wild-LIFE test suite"
# echo "                       --------------------"
# echo ""
# echo "interpreter: $WLIFE"
# echo ""
# echo ""
# echo ""




# Run the test suite
foreach I ($*)

   echo $I

if(-e LF/$I:r.lf) then

# Remove any core dumps
   rm -f core

# Run Wild-LIFE
   (echo 'load("LF/' $I:r.lf '")?' | tr -d ' ' ;echo "" ; \
	cat IN/$I:r.in  ; echo "halt?") | \
	($WLIFE |  \
egrep -v '(Loading|already loaded|Version|customizing|Copyright|Garbage|Exiting|X interface)' > OUT/$I:r.out \
        ) |& \
        sed "s/.......s cpu (.*)//" > ERR/$I:r.err

# Check for core dump
   if(-e core) then
	echo "          ***    C O R E   D U M P  ! !       ***"
   endif

# Calculate the differences
   (diff OUT/$I:r.out REFOUT/$I:r.refout > REFDIFF/$I:r.refdiff) >& /dev/null
   (diff ERR/$I:r.err REFERR/$I:r.referr > ERRDIFF/$I:r.errdiff) >& /dev/null


# Report them to the developer
   if(`wc -c < REFDIFF/$I:r.refdiff` != 0) then
        echo "          *** output does not match reference ***"
   else
        rm -f REFDIFF/$I:r.refdiff
   endif

   if(`wc -c < ERRDIFF/$I:r.errdiff` != 0) then
	echo "          ***  errors do not match reference  ***"
   else
        rm -f ERRDIFF/$I:r.errdiff
   endif

else
   echo "          ***  no such test file  ***"
endif

end

echo ""
echo "Test finished: `date`"
echo ""
