#! /bin/bash

# One test fails with Python 3.11 and six with Python 3.12.  This
# script generates appropriate code for the pytest call.  The Python 3.12
# failures have been reported upstream to:
# https://github.com/microsoft/debugpy/issues/1490
# The Python 3.11 failures are more likely to do with the package versions
# we have of something, as they work in the upstream GitHub test environment.

# This script is called from both debian/rules and from the
# autopkgtest suite.  Because many of the test exclusions include
# parentheses, and they are called in different ways, we take an
# argument specifying rules or autopkgtest

quoting=$1
if [ "$quoting" != rules ] && [ "$quoting" != autopkgtest ]
then
    echo "Argument must be 'rules' or 'autopkgtest'" >&2
    exit 1
fi

EXCLUDES=(
    "tests/debugpy/test_attach.py::test_attach_pid_client[program-int]"
    "tests/debugpy/test_attach.py::test_attach_pid_client[program-str]"
    "tests/debugpy/test_flask.py::test_flask_breakpoint_no_multiproc[launch-template]"
    "tests/debugpy/test_flask.py::test_flask_breakpoint_no_multiproc[launch-code]"
    "tests/debugpy/test_flask.py::test_flask_template_exception_no_multiproc[launch]"
    "tests/debugpy/test_flask.py::test_flask_exception_no_multiproc[launch-handled]"
    "tests/debugpy/test_flask.py::test_flask_exception_no_multiproc[launch-unhandled]"
    "tests/debugpy/test_flask.py::test_flask_breakpoint_multiproc[launch]"

)

DESELECTS=()
if [ $quoting = rules ]
then
    for test in "${EXCLUDES[@]}"
    do
        DESELECTS+=("--deselect='$test'")
    done
    echo ${DESELECTS[*]}
else
    for test in "${EXCLUDES[@]}"
    do
        DESELECTS+=("--deselect=$test")
    done
    echo "${DESELECTS[*]}"
fi
