# -*- sh -*-
# vim: syntax=sh

. environment 2> /dev/null || echo "WARNING: environment not found, will try to guess" >&2
. lib/util

# support manual execution of the test
test -z "$TOOLS" && {
    TOOLS=$(readlink -f $(cd ..; make show var=OBJ)/debug/tools)
    echo "set TOOLS=$TOOLS"
}

test -d "$TOOLS" -a -f "$TOOLS/divine" || {
    echo "TOOLS has to be directory with your divine binary."
    exit 1
}

if echo $TOOLS | grep -q "^C:"; then # MSYS hack
    TOOLS=`echo -n "$TOOLS" | sed -e 's,C:,/c,;s,\\\\,/,;'`
fi

if test -z "$MPIEXEC"; then
    MPIEXEC=false
else
    MPIEXEC=$(readlink -f `which $MPIEXEC`)
fi

chmod +x lib/check lib/run lib/sim lib/ordgrep

PATH="$PWD/lib:$TOOLS:$TOOLS/../llvm/bin:$PATH"
extracheck=:
export cesmiext=.so
test "$WIN32" = 1 && cesmiext=.dll

if test -n "$TESTS" && test -z "$TODO" && echo "$0 $1" | grep -q todo; then
    exit 200
fi
if test -n "$TESTS" && test "$TODO" = "only" && echo "$0 $1" | grep -qv todo; then
    exit 200
fi

rm -rf __test_work_dir.$TEST_SLOT
mkdir -p __test_work_dir.$TEST_SLOT
cd __test_work_dir.$TEST_SLOT

trap "check debris" EXIT
set -e -o pipefail
test -n "$SILENT" || set -x
