#! /bin/sh
#
# usage: runtest [<testfile>...]
# without args, runs all *.test files in the current directory
#

MAKE="make MODE=debug"

# Test if we are running on OMNeT++ 5.1 as we did not have the _dbg suffix for debug binaries on 5.1
# (this can be removed if OMNeT++ 5.1 compatibility is no longer needed)
#
OMNETPP_51=$(grep "OMNETPP_VERSION = 5.1" $(opp_configfilepath))
if [ -z $OMNETPP_51 ]; then
DBG_SUFFIX="_dbg"
else
DBG_SUFFIX=""
fi

TESTFILES=$*
if [ "x$TESTFILES" = "x" ]; then TESTFILES='*.test'; fi
if [ ! -d work ];  then mkdir work; fi

cp -pPR lib work/       # OSX does not support cp -a

opp_test gen $OPT -v $TESTFILES || exit 1

echo
(cd work; opp_makemake -f --deep -lINET$DBG_SUFFIX -L../../../src -P . --no-deep-includes -I../../../src; $MAKE) || exit 1

echo
PATH=$PATH:../../src opp_test run -p work$DBG_SUFFIX -a "--check-signals=false -lINET " $OPT -v $TESTFILES || exit 1

echo
echo Results can be found in ./work