# includable shell script to make test scripts smaller

set -e

if [ -z "${testfilter}" ]; then
   if [ -x /usr/bin/van-pydeb ]; then
       testfilter="-m $(van-pydeb src_to_py $(dpkg-parsechangelog -c1 -ldebian/changelog | grep 'Source: ' | sed 's/Source: //'))"
   else
       echo "Could not find van-pydeb to guess the python package name. You should have your tests depend on it or you "
       echo "must specify testfilter variable, something like -p package_name, see zope-testrunner --help for details."
       exit 1
   fi
fi 

PYVERS=$(pyversions -vr debian/control)
for version in ${PYVERS}; do
    py_libdir_sh=$(python${version} -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())')
    echo Running tests for python${version}: /usr/bin/zope-testrunner${version} -k --test-path ${py_libdir_sh} ${testfilter}
    /usr/bin/zope-testrunner${version} -k --test-path ${py_libdir_sh} ${testfilter}
done
