#!/bin/sh
# This script is used both as autopkgtest and at package build time.

set -e

export GNUSTEP_MAKEFILES=/usr/share/GNUstep/Makefiles

if [ -z $AUTOPKGTEST_TMP ]; then
# The script is invoked from the override_dh_auto_test target.
    STEXEC=test/usr/bin/stexec
    export GNUSTEP_CONFIG_FILE=`pwd`/test.conf
    export LD_LIBRARY_PATH=/usr/lib:./test/usr/lib
    export ADDITIONAL_INCLUDE_DIRS=-I`pwd`/test/usr/include/GNUstep
    export ADDITIONAL_LIB_DIRS=-L`pwd`/test/usr/lib
else
# Running as autopkgtest.
    STEXEC=stexec
fi

make -C Testing/leaks messages=yes
echo "Running leaktest..."
./Testing/leaks/obj/leaktest
make -C Testing/leaks clean

# Some scripts are buggy but nevertheless exit with success.
for f in `find Testing -name \*.st`; do
    echo "Executing $f..."
    $STEXEC $f
done

for f in `find Examples/Smalltalk -name \*.st`; do
    case $f in
        # The shell script requires the ReadlineTranscript module which
        # is not built.
        *shell* )
        continue
        ;;
    esac
    echo "Executing $f..."
    $STEXEC $f
done

exit 0
