#!/bin/sh

set -e -u

# run initial build steps to generate the test script
dh_autoreconf 2>&1
dh_auto_configure 2>&1

# examples are also used for testing
cp --archive run_tests.py examples/ test/ "$AUTOPKGTEST_TMP"

cd "$AUTOPKGTEST_TMP"

# symlink all executables installed by the re2c package
ln --verbose --symbolic /usr/bin/re2* "$AUTOPKGTEST_TMP"
# symlink the syntax files
mkdir -p "$AUTOPKGTEST_TMP"/include/syntax
ln --verbose --symbolic /usr/share/re2c/stdlib/* "$AUTOPKGTEST_TMP"/include/syntax

# Check for multiprocessing.Pool() support, required by the testsuite
if $(python3 -c "from multiprocessing import Pool; pool = Pool(); pool.close()" >/dev/null 2>&1); then
	python3 ./run_tests.py
else
	echo "Support for multiprocessing.Pool() missing, skipping testsuite"
fi
