#!/bin/bash
#
# Run system tests on a sifflet executable, which may be optionally
# specified as the command line argument:
#
# ./system-tests.sh PATH-TO-SIFFLET-EXECUTABLE
#
# The default PATH-TO-SIFFLET-EXECUTABLE is in the ../bin directory
# from where this script is located.

TEST_DIR=`dirname $0`
# Figure out which sifflet program is to be tested
if [ $# -eq 1 ]; then
  Prog=$1
else
  Prog=$TEST_DIR/../.cabal-sandbox/bin/sifflet
fi

echo "Using $Prog"

# Check if file exists, is regular file and executable
if [ -f $Prog ] && [ -x $Prog ]; then

    $Prog --call fact 4
    $Prog --show fact
    $Prog --file $TEST_DIR/data/systest1.siff --show demoFunction
    $Prog --show length
    $Prog --show sum
    $Prog --show buggySum
    $Prog --show buggySumFromZero

else

    echo "$Prog is does not exist, or is not an executable program file."
    exit 1
fi
