#!/bin/sh

set -eu

# remove autopkgtest's unreadable (for postgres) temp dir
unset TMPDIR

VERSIONS=$(pg_buildext supported-versions)

cd tests

for version in $VERSIONS; do
	#for DIR in test*/; do # takes a LOOONG time
	for DIR in test1; do
		TEST=$(basename $DIR)
		echo "############### $TEST ###############"
		if ! PGBINDIR=/usr/lib/postgresql/$version/bin pg_virtualenv -v $version \
		    ./run_test.sh $TEST 2>&1; then
			EXIT=1
			for log in ${TMPDIR:-/tmp}/slony-regress.*/slonik.log*; do
				test -e $log || continue
				echo "$log:"
				cat $log
			done
		fi
	done
done

rm -rf ${TMPDIR:-/tmp}/slony-regress.*/

exit ${EXIT:-0}
