#!/bin/sh
#
# This autopkgtest runs only specific test files instead of the full
# suite, as upstream test suite is very time consuming.

set -e -u

TEST_FILES="test_base.py test_scipy.py test_rosetta.py test_numpy_func3.py"
# * test_base: basic tests.
# * test_cases: suggested by upstream [1].
# * test_scipy: suggested during initial sponsorship, for scipy/numpy
#   coverage.
# * test_rosetta: suggested during initial sponsorship, for additional
#   user-oriented coverage.
# * test_numpy_func3: suggested during initial sponsorship, for
#   additional blas-specific coverage.
#
# [1] https://github.com/serge-sans-paille/pythran/issues/908#issuecomment-945378742

# TestNumpyFunc3.test_interp is flakey at levels 6,7,8
# especially with complex numbers (_7c etc) and depending on BLAS implementation
# i386 is flakey also in the real variant, so skip all _6,_7,_8
# see https://github.com/serge-sans-paille/pythran/issues/2000

# test_rosetta test_repeat_string_run0 fails with gcc-12, cf Bug#1016155,
# see https://github.com/serge-sans-paille/pythran/issues/2011
TEST_SELECTOR="not ( test_interp_6 or interp_7 or test_interp_8 or test_repeat_string_run0 )"

DEB_HOST_ARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
if [ "${DEB_HOST_ARCH}" = "i386" ] ; then
    export CXXFLAGS="-march=native"
fi

# Copy upstream "pythran.tests" to a new package, as it is not part of
# the installed packages but the test files import from it.
cp -r pythran/tests $AUTOPKGTEST_TMP/pythran_tests
cd $AUTOPKGTEST_TMP/pythran_tests
find . -type f -name "*.py" -print0 | xargs -0 sed -i 's|pythran\.tests|pythran_tests|g'

# test_rosetta contains hard-coded references to a file relative to the
# package directory.
sed -i 's|pythran/tests/rosetta/read_conf.cfg|rosetta/read_conf.cfg|g' rosetta/*

for py in $(py3versions -s 2>/dev/null); do
    echo "Running testsuite with $py:"
    for test_file in $TEST_FILES; do
        $py -m pytest $test_file -k "${TEST_SELECTOR}"
    done
done
