#!/bin/sh

if [ -z "$TMPDIR" ]; then
	TMPDIR=/tmp
fi

OUTFILE="${TMPDIR}/regress_lwgeom_out_$$"

echo "Running LWGEOM Regression Test..."
echo "Output file is: '${OUTFILE}'"
echo ""
echo "Building a database for testing (postgis_reg)."

DB=postgis_reg
createdb $DB > /dev/null

echo "Building postgis support in it."
echo ""

createlang plpgsql $DB > /dev/null
psql -f ../lwpostgis.sql $DB > /dev/null 2>&1

echo "there shouldnt be any real output produced after this line."
echo ""

psql -tA < lwgeom_regress.sql $DB 2>&1 | grep -v "^INSERT" > "${OUTFILE}"
diff lwgeom_regress_expected "${OUTFILE}"
sleep 1
dropdb $DB > /dev/null
