#!/bin/bash

set -e -u

mkdir -p "${AUTOPKGTEST_TMP}"/griffecli
mkdir -p "${AUTOPKGTEST_TMP}"/griffelib

cp -a docs "${AUTOPKGTEST_TMP}"
cp -a packages/griffecli/tests "${AUTOPKGTEST_TMP}"/griffecli
cp -a packages/griffelib/tests "${AUTOPKGTEST_TMP}"/griffelib

for py3vers in $(py3versions -s); do
    echo
    echo "***************************"
    echo "*** Testing with ${py3vers}"
    echo "***************************"
    echo
    cd ${AUTOPKGTEST_TMP} && \
        echo "Content of current working folder:\n" && \
        ls -la && \
        echo "Running tests...\n" && \
        for GRIFFE_PACKAGE in griffecli griffelib ; do \
            cd ${AUTOPKGTEST_TMP}/${GRIFFE_PACKAGE} && \
            PYTHONPATH=. ${py3vers} -m pytest -sv \
            --ignore tests/test_api.py \
            -k "not test_load_git \
                and not test_load_git_errors \
                and not test_meson_python_file_handling" tests && \
            rm -rf .pytest_cache || exit 1
        done
done

echo

exit 0
