#!/bin/sh

MODSQL=../modsql
MODSQL_OPTS="-HHSv"

if [ ! -x $MODSQL ]; then
  echo "Cannot find executable '$MODSQL'!"
  echo "You may need to run make."
  exit 1
fi

for i in *.sql; do
  printf "Running $i ..."
  out=`echo $i |sed 's/.sql/.results/'`
  if [ ! -f $out ]; then
    # just run the test
    $MODSQL $MODSQL_OPTS $i &>$out
    echo " complete."
  else
    # run test and compare
    $MODSQL $MODSQL_OPTS $i &>$out.new
    if ! diff $out $out.new >/dev/null; then
      echo ' FAILED!'
    else
      echo " passed."
      rm -f $out.new
    fi
  fi
done
