This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/dirty/run-dirty-tests.sh
Emmanuel BENOîT c18bdc2d1f Dirty SQL test system
* Added a system that allows "dirty" tests to be written. These tests
actually need to change the database, so a temporary test database must
be created to run them.
2012-01-14 09:02:24 +01:00

37 lines
1 KiB
Bash
Executable file

#!/bin/bash
if [ -z "$TEST_DATABASE" ]; then
echo "Missing TEST_DATABASE environment variable"
exit 1;
fi
echo
echo 'Running "dirty" database tests'
echo
find -mindepth 1 -maxdepth 1 -type d | sort | while read testdir; do
[ -f "$testdir/run-test.sql" ] || continue
echo "Dirty test $testdir"
echo "--------------------------------------------"
echo
echo "Creating temporary database ..."
echo "DROP DATABASE IF EXISTS dirty_tests; CREATE DATABASE dirty_tests TEMPLATE $TEST_DATABASE;" \
| psql -vQUIET=1 -vON_ERROR_STOP=1 $TEST_DATABASE || exit 1
if [ -f "$testdir/prepare.sql" ]; then
echo "Preparing database ..."
( cd .. && exec psql -vQUIET=1 -vON_ERROR_STOP=1 --file "dirty/$testdir/prepare.sql" dirty_tests ) || exit 1
fi
echo "Running main test ..."
( cd .. && pg_prove -d dirty_tests dirty/$testdir/run-test.sql ) || exit 1
echo "Dropping temporary database ..."
echo -e "DROP DATABASE IF EXISTS dirty_tests;" \
| psql -vQUIET=1 -vON_ERROR_STOP=1 $TEST_DATABASE || exit 1
echo
done