#!/bin/sh

set -e

if [ -z "$DEBUG" ]; then
    export DEBUG=shelly-testsuite
fi

SUITE=./dist/build/shelly-testsuite/shelly-testsuite

rm -f shelly-testsuite.tix
cabal build

if [ ! -f $SUITE ]; then
    cat <<EOF
Testsuite executable not found, please run:
    cabal configure --enable-tests
then
    cabal build
Note this script should be run from the root of the checkout
EOF
    exit;
fi

$SUITE $*

DIR=dist/hpc

rm -Rf $DIR
mkdir -p $DIR

EXCLUDES='TestMain
CopySpec
EnvSpec
FailureSpec
FindSpec
Help
Main
MoveSpec
ReadFileSpec
WhichSpec
WriteSpec
RunSpec
SshSpec
'

EXCL=""

for m in $EXCLUDES; do
    EXCL="$EXCL --exclude=$m"
done

hpc markup $EXCL --destdir=$DIR shelly-testsuite >/dev/null 2>&1

cat <<EOF
Test coverage report written to $DIR.
EOF