#! /bin/sh

set -e

PYS=$(py3versions -s)

# 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"

# 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).
for py in $PYS; do
    echo "Testing with $py:"
    tempdir=$(mktemp -d -p "$AUTOPKGTEST_TMP")
    # See https://github.com/spyder-ide/spyder/issues/17104
    ( cd spyder/app/tests/spyder-boilerplate && \
          HOME="$tempdir" $py -m pip install --no-deps -q -e . )
    for slow in "" "--run-slow"; do
        CI=true HOME="$tempdir" \
          xvfb-run -a -s "-screen 0 1024x768x24 +extension GLX" \
          $py runtests.py --homedir="$tempdir" $EXCLUDE $slow "$@"
    done
done
