#!/bin/bash
# Todo: Find a way to make this not suck.

ulimit -t 60 # Sometimes GHC ends in a spin loop, and this is easier than debugging

[[ -e test/quackCheck.hs ]] || { echo "Are you running me from the wrong directory?"; exit 1; }
[[ $1 == -v ]] && pattern="" || pattern="FAIL"

find . -name '*.hs' -exec bash -c '
grep -v "^module " "$1" > quack.tmp.hs
./test/quackCheck.hs +names quack.tmp.hs
' -- {} \; 2>&1 | grep -i "$pattern"
result=$?
rm -f quack.tmp.hs hugsin

if [[ $result == 0 ]]
then
  exit 1
else
  exit 0
fi