#! /bin/sh

rc=0
autoquit=
valgrind=
vopt=

while [ $# -gt 0 ] ; do
  case $1 in
    valgrind) valgrind=valgrind; vopt=-q;;
    autoquit) autoquit=autoquit;;
  esac
  shift
done         

/bin/rm -f test.*
/bin/rm -f test-*

echo "*** Running distributed tests ***"

for x in infiles/* ; do
  file=`basename $x`
  $valgrind $vopt ../src/pmw -norc -testing -F ../fontmetrics -H ../PSheader \
    -MF ../psfonts -SM ../macros -o test.ps infiles/$file

  diff -u outfiles/$file.ps test.ps >test.diff
  if [ $? != 0 ] ; then
    mv test.diff test-$file.diff
    echo "*** $file test failed - see test-$file.diff ***"
    if [ "$autoquit" = "autoquit" ]; then exit 1; fi 
    rc=1
  else
    echo $file test succeeded
  fi
done

# If all is well and we are in a development environment where the wider set of 
# tests is available, run them too.

if [ $rc = 0 ]; then
  /bin/rm -f test.*
  /bin/rm -f test-*
  if [ -x ../testing/RunTests ]; then
    (cd ../testing; RunTests $autoquit $valgrind)
  rc=$?   
  fi    
fi

exit $rc

# End
