# /bin/sh -x
# $Id$
# $URL$

OK="\033[1;32m OK  \033[0m"
FAIL="\033[1;31m  FAILED  \033[0m"

file=$1

if test -x $file
   then
   	\rm -f $file.diff
	\rm -f testoutput/$file.tmp
	\rm -f testoutput/$file.err*
	\rm -f testoutput/$file.diff
   	echo -n "testing  $file "
	./$file > testoutput/$file.tmp 2> testoutput/$file.err.1
	diff --ignore-matching-lines=".?*-annotation .?*" --ignore-matching-lines=".http://www.w3.org/1999.?*" --ignore-matching-lines=".*generator=.*" testoutput/$file.tmp $file.ok > testoutput/$file.diff 2>& 1
	if [ $? -ne 0 ];
	then sed 's/\/.*\///g' testoutput/$file.err.1 > testoutput/$file.err
	     diff testoutput/$file.err $file.ok > testoutput/$file.diff 2>& 1;
	     if [ $? -ne 0 ];
	     then
            echo -e $FAIL;
	     	echo "differences logged in testoutput/$file.diff";
	     	echo "stderr messages logged in testoutput/$file.err";
            exit 1
	     else
            echo -e $OK
            \rm -f testoutput/$file.diff
            \rm -f testoutput/$file.err
            exit 0
	     fi
	else
	    \rm -f testoutput/$file.diff
	    echo -e $OK
            exit 0
	fi
fi
