#!/bin/csh
#
# A regressions test for coral
#
# Set a few varibles
#
# This scripts depends on 2 directories: the data directory, there the files containing
# the correct output are, and the diff directory, which contains the files describing
# the differneces between the expected resultsa and the actual results.
#
#
##
set coral = coral			# command to call coral
set rg = $cwd				# current working directory
set test = $rg/testsuite		# where testing files are 
set data = $rg/testdata			# where benchmark files are.
set diffdir = $rg/testdiff		# where differences go.
set filter = "nawk -f $rg/strip.awk "	# filter out beginning and end messages
set diff  = diff			# set the diff program
set argc = $#argv			# the number of args from command line

# if sysV sort is available, use it
set sort = sort                        # the sort routine to use
#
# if BSD sort is being used, some of the programs will produce output lines 
# that are too long for sort to handle.
#
#set sort = sort
#
# set up the single output files.
#
@ x = 0
foreach i ($argv)			# for each i in 
	@ x++
	switch($argv[$x])
	case "-h":
	case "-help":
		goto usage
		breaksw
	case "-s":
		if($argc == 1) goto usage
		@ y = $x + 1
		set sfiles = "$argv[${y}]"
		goto next
		breaksw
	default:
		echo Error in specifying command line options
		goto usage
		breaksw
	endsw
end

next:
#
# now, if sfiles has not been set, set it to the defaults
# NOTE: If you wish to add new files to be tested, add them to this list.
#
if($?sfiles == 0) then
set sfiles =   (declac1 declac12 declac2 declac4 declad2 declad3 declad4 \
		declad5 declad7 declad8 declad9 declne1 declne2 declne3 \
		declne4 declne5 declse1 declse2 declse3 declse4 declse5 \
		declse6 declse7 extens1 impmod3 impmod4 mod3 mod4 mod5 \
		mod6 mod7 mod8 mod9 pipe1 pipe2 pipe3 pipe4)
endif

onintr end 				# exit gracefully on end
echo " "
echo "Cleaning up old files."
echo " "
/bin/rm -f $diffdir/*.diff >& /dev/null

#
# If the test directory does not exist, exit
#
#if(!(-e $test)) then
#	echo " No test directory !"
#	exit 1
#endif
#
#


#
#
# If the data directory has not been written, create it and put all the output into the
# data directory.
#
#
if(!(-e $data)) then
	mkdir $data
	echo " "
	echo "Creating the data directory."
	echo " "
	set createoutput
endif

if(!(-e $diffdir)) then
	mkdir $diffdir
	echo "Creating the diff directory."
endif

####
#
#
#
# This will run a set of files to make sure that they are giving the right answers.
#
####
initial:
foreach i ($sfiles)
	echo -n "Testing the " $i " program..."
	if($?createoutput) then
		$coral -q < $test/${i}.X |& $filter | $sort >& $data/${i}.out
#		$coral -q < ${i}.X |& $filter | $sort >& $data/${i}.out
		echo "done."
		grep -si error $data/${i}.out
		@ s = $status
		if ($s == 0) echo "*** Errors occurred creating" $data/${i}.out 
	else
		$coral -q < $test/${i}.X |& $filter | $sort |& $diff - $data/${i}.out > $diffdir/${i}.diff
#		$coral -q < ${i}.X |& $filter | $sort |& $diff - $data/${i}.out > $diffdir/${i}.diff
		echo "done."
#		if (!(-z $diffdir/${i}.diff)) then
#			echo "**** There might be problems with the " $i " program. *** "
#		endif
	endif
end

########
#
# Clean up.
#
#######
end:
if(!($?createoutput)) then
foreach i (`ls $diffdir`)
	set i = $diffdir/$i
	if(!(-z $i)) then
		set s = $i:t
		set s = $s:r
		echo "There are differences between expected output and actual ouput in the $s file."
	endif
end
endif
echo " "
echo End of tests.
exit 0

usage:

echo Usage: test_suite \[-help\] \[-s \"list of files to test\"\]
exit 1


