#!/bin/sh

execdir="$PWD"

for f in $execdir/tests/*_test
do
    # check that the filename exists.  If there are no files,
    # Bourne shell will treat $execdir/tests/*_test like a
    # literal string!
    [ -f "$f" ] || continue

    echo "------------------------------------------------------"
    echo "Running unit tests from file $f"
    echo "------------------------------------------------------"

    if [ -n "${PARVALGRINDOPTS+set}" ]
    then
        PARBINARY="valgrind $PARVALGRINDOPTS $f"
    else
	PARBINARY="$f"
    fi

    # 77 is the exit status for a test that does not apply on this platform
    $PARBINARY
    status=$?
    if [ $status -ne 0 ] && [ $status -ne 77 ]
    then
        echo "ERROR: $f failed." >&2
        exit 1
    fi

    echo "------------------------------------------------------"
    echo "Unit test complete for file $f"
    echo "------------------------------------------------------"
done

for f in $execdir/tests/*_test.exe
do
    # check that the filename exists.  If there are no files,
    # Bourne shell will treat $execdir/tests/*_test like a
    # literal string!
    [ -f "$f" ] || continue

    echo "------------------------------------------------------"
    echo "Running unit tests from file $f"
    echo "------------------------------------------------------"

    wine $f
    status=$?
    if [ $status -ne 0 ] && [ $status -ne 77 ]
    then
        echo "ERROR: $f failed." >&2
        exit 1
    fi

    echo "------------------------------------------------------"
    echo "Unit test complete for file $f"
    echo "------------------------------------------------------"
done

exit 0
