#! /bin/sh

set -e

# If arguments are supplied to this function, they will be passed to
# the runtests.py invocation.

# Some tests have to be excluded for various reasons

EXCLUDE=""

# This test causes pytest to segfault.
# Reported to: https://github.com/spyder-ide/spyder/issues/17651
EXCLUDE="${EXCLUDE} --deselect=spyder/app/tests/test_mainwindow.py"

# This test raises an error.
# Reported to: https://github.com/spyder-ide/spyder/issues/17651
EXCLUDE="${EXCLUDE} --deselect=spyder/plugins/editor/widgets/tests/test_hints_and_calltips.py::test_get_hints"

# This set of tests repeatedly fails on i386
# Reported to: https://github.com/spyder-ide/spyder/issues/17651
if [ "$(dpkg --print-architecture)" = i386 ]
then
    EXCLUDE="${EXCLUDE} --deselect=spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py"
fi

# We need to set up a home directory for some of the pytest tests, but
# we cannot do so within the script as it gets deleted too early, before
# the pytest finalisers have run.  So we set it up it here (and
# autopkgtest will delete it afterwards).
PYS=$(py3versions -s)
for py in $PYS; do
    echo "Testing with $py:"

    tempdir=$(mktemp -d -p "$AUTOPKGTEST_TMP")
    export HOME="$tempdir"

    # We need to install the test plugin.
    # See https://github.com/spyder-ide/spyder/issues/17104
    ( cd spyder/app/tests/spyder-boilerplate && \
        $py -m pip install --no-deps -q -e . )

    export CI=true
    for slow in "" "--run-slow"
    do
        debian/tests/run_pytest.py \
          xvfb-run -a -s "-screen 0 1024x768x24 +extension GLX" \
          $py runtests.py --homedir=$tempdir $EXCLUDE $slow "$@"
    done
done
