#!/bin/sh

DBNAME=plperl_test
export DBNAME

echo "**** Destroy old database $DBNAME ****"
dropdb $DBNAME

sleep 1

echo "**** Create test database $DBNAME ****"
createdb $DBNAME

echo "**** Create procedural language plperl ****"
createlang plperl $DBNAME

echo "**** Create procedural language plperlu ****"
createlang plperlu $DBNAME


echo "**** Running test queries ****"
psql -q -n -e $DBNAME <test_queries.sql > test.out 2>&1

if diff test.expected test.out >/dev/null 2>&1 ; then
    echo "    Tests passed O.K."
    rm test.out
else
    echo "    Tests failed - look at diffs between"
    echo "    test.expected and test.out"
fi

echo "**** Running plperlu_plperl tests ****"
psql -q -n -e $DBNAME <plperlu_plperl.sql > plperlu_plperl.out 2>&1
if diff plperlu_plperl.expected plperlu_plperl.out >/dev/null 2>&1 || \
	diff plperlu_plperl.expected_alt plperlu_plperl.out >/dev/null 2>&1
then
    echo "    Tests passed O.K."
    rm plperlu_plperl.out
else
    echo "    Tests failed - look at diffs between"
    echo "    plperlu_plperl.expected{_alt} and plperlu_plperl.out"
fi


