#!/bin/sh
# $Id: check.sh,v 1.8 2003/12/25 19:26:17 fp010 Exp $
# hacked up by hvr inspired by fptest

HUGS=hugs

if [ -z "$1" -o -z "$2" -o "$#" -gt 2 ]; then
  echo "usage: $0 <hs module> <hs eval file>"
  exit 1
fi

TESTNAME=$1
INPUTS=$2
if [ ! -f "$INPUTS" ]; then
  echo "test-file '$INPUTS' not found!"
  exit 2
fi

(echo "True" | ${HUGS} $TESTNAME) > tmp.true 2> /dev/null || {
  echo "**Error**: I had problems executing \`${HUGS}' (rc=$?) -- aborting..."
  echo 
  exit 77
}

N=1

cat "$INPUTS" | sed 's/\\/\\\\/g;s/^[ 	]*//;s/[ 	]*$//' | while read; do
	[ -z "${REPLY}" ] && continue
	echo "${REPLY}" | grep '^--' && continue
	# since "${REPLY}" is not an empty line... go for it!
        echo -n "Test $N => $REPLY"
	echo "${REPLY}" | ${HUGS} $TESTNAME > tmp.testout
	if cmp -s tmp.true tmp.testout; then
	    echo " : OK"
	else
	    echo " : FAILED; output was:"
	    echo "/---------------------------------------------------------------------------"
            #cat tmp.testout
	    # output only the significant part
            diff tmp.true tmp.testout | grep '^>'
	    echo "\\---------------------------------------------------------------------------"
	    echo "** Test $N FAILED! :-( **"
	    let RC=N
            exit $N
        fi
	let N=N+1
done
RC=$?
rm -f tmp.true tmp.testout
exit $RC

