#!/bin/bash
cd legacyworlds-server-data/db-structure
if ! [ -f db-config.txt ]; then
cat > db-config.txt <<EOF
admin=$USER
db=tests
user=tests
password=tests
EOF
fi
export TEST_DATABASE="`grep ^db= db-config.txt | sed -e s/.*=//`"
export TEST_USER="`grep ^user= db-config.txt | sed -e s/.*=//`"
echo
echo "======================================================================"
echo "LOADING DATABASE DEFINITION ..."
psql -vQUIET=1 -vON_ERROR_STOP=1 -e --file database.sql || exit 1
if ! [ -d tests/admin ] && ! [ -d tests/user ]; then
echo "WARNING: no unit tests to run"
exit 0
echo "LOADING TEST FRAMEWORK ..."
psql -vQUIET=1 -f tests/pgtap.sql $TEST_DATABASE || exit 1
echo "RUNNING DATABASE TESTS ..."
cd tests
if [ -d admin ]; then
pg_prove -d $TEST_DATABASE `find admin/ -type f -name '*.sql'` || exit 1
if [ -d user ]; then
pg_prove -U $TEST_USER -d $TEST_DATABASE `find user/ -type f -name '*.sql'` || exit 1
if [ -x dirty/run-dirty-tests.sql ]; then
( cd dirty; exec ./run-dirty-tests.sql ) || exit 1