From: Paul Ramsey Date: Wed, 16 Mar 2011 13:03:12 +0000 (+0000) Subject: Jeff Adams patch to allow pre/post actions in regression tests X-Git-Tag: 2.0.0alpha1~1896 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6a6199ff702fa13f49a9885950eb83303fd2260;p=postgis Jeff Adams patch to allow pre/post actions in regression tests git-svn-id: http://svn.osgeo.org/postgis/trunk@6906 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/regress/README b/regress/README index 396bf8fb6..add62da31 100644 --- a/regress/README +++ b/regress/README @@ -15,6 +15,15 @@ How to add a regression test 3. Edit regress/Makefile adding to the TESTS variable. Any _expected.in files need to be added to the PREPROC variable. +Optional: + If your test has unusual setup or teardown requirements, you may create + any of the following optional files (they will run in this order): + /regress/-pre.sh + /regress/-pre.sql (run via psql) + (The test itself is run here.) + /regress/-post.sql (run via psql) + /regress/-post.sh + Notes about changes in regression tests introduces with PostGIS 1.1.0 --------------------------------------------------------------------- diff --git a/regress/run_test b/regress/run_test index 24cfe47e6..67ec01a28 100755 --- a/regress/run_test +++ b/regress/run_test @@ -95,6 +95,40 @@ fail () FAIL=`expr $FAIL + 1` } +# +# run_simple_sql +# +# Run an sql script and hide results unless it fails. +# +# SQL input file name is $1 +# +run_simple_sql () +{ + _sql="$1" + + if [ ! -r "$_sql" ]; then + fail "can't read $_sql" + return 1 + fi + + TMPFILE="${TMPDIR}/test_${RUN}_tmp" + + # Dump output to a temp file. + ${PSQL} -tXA < "${_sql}" ${DB} > ${TMPFILE} 2>&1 + # Check if psql errored out. + if [ $? -gt 0 ]; then + fail "Unable to run sql script $_sql" "${TMPFILE}" + return 1 + fi + # Check if psql produced any error output. + grep "^ERROR:" "${TMPFILE}" + if [ $? -eq 0 ]; then + fail "Errors while running sql script $_sql" "${TMPFILE}" + return 1 + fi + rm ${TMPFILE} +} + # # run_simple_test # @@ -165,7 +199,7 @@ run_simple_test () # Load a shapefile with different methods, create a 'select *' SQL # test and run simple test with provided expected output. # -# SHP input is ${TEST}.shp, expected output is {$TEST}_expected +# SHP input is ${TEST}.shp, expected output is {$TEST}.expected # run_loader_test () { @@ -516,6 +550,28 @@ while [ -n "$1" ]; do RUN=`expr $RUN + 1` + # Check for a "-pre.sh" file in case there are non-SQL setup tasks needed before + # the test can be run. + if [ -r "${TEST}-pre.sh" ]; then + "${TEST}-pre.sh" + if [ $? -gt 0 ]; then + fail " setup script failed" + continue + else + show_progress + fi + fi + + # Check for a "-pre.sql" file in case there is setup SQL needed before + # the test can be run. + if [ -r "${TEST}-pre.sql" ]; then + if run_simple_sql "${TEST}-pre.sql"; then + show_progress + else + continue + fi + fi + # Check .shp *before* .sql as loader test would # create the .sql if [ -r "${TEST}.shp" ]; then @@ -532,6 +588,22 @@ while [ -n "$1" ]; do continue fi + # Check for a "-post.sql" file in case there is teardown SQL needed after + # the test has been run. + if [ -r "${TEST}-post.sql" ]; then + if ! run_simple_sql "${TEST}-post.sql"; then + echo " ... but cleanup sql failed!" + fi + fi + + # Check for a "-post.sh" file in case there are non-SQL teardown tasks needed after + # the test has been run. + if [ -r "${TEST}-post.sh" ]; then + "${TEST}-post.sh" + if [ $? -gt 0 ]; then + echo " ... but cleanup script failed!" + fi + fi done