From de9188f3c5f8b26d6d444a0d971e63d66c54243a Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 9 Feb 2016 15:47:59 +0000 Subject: [PATCH] Add --dumprestore switch to ./run_test.pl See #3444 git-svn-id: http://svn.osgeo.org/postgis/trunk@14651 b70326c6-7e19-0410-871a-916f4a2858ee --- regress/run_test.pl | 47 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/regress/run_test.pl b/regress/run_test.pl index aa1944e25..cf49b4963 100755 --- a/regress/run_test.pl +++ b/regress/run_test.pl @@ -52,6 +52,7 @@ my $OPT_CLEAN = 0; my $OPT_NODROP = 0; my $OPT_NOCREATE = 0; my $OPT_UPGRADE = 0; +my $OPT_DUMPRESTORE = 0; my $OPT_WITH_TOPO = 0; my $OPT_WITH_RASTER = 0; my $OPT_WITH_SFCGAL = 0; @@ -69,6 +70,7 @@ GetOptions ( 'nodrop' => \$OPT_NODROP, 'upgrade' => \$OPT_UPGRADE, 'upgrade-path=s' => \$OPT_UPGRADE_PATH, + 'dumprestore' => \$OPT_DUMPRESTORE, 'nocreate' => \$OPT_NOCREATE, 'topology' => \$OPT_WITH_TOPO, 'raster' => \$OPT_WITH_RASTER, @@ -332,6 +334,11 @@ if ( $OPT_UPGRADE ) $libver = sql("select postgis_lib_version()"); } +if ( $OPT_DUMPRESTORE ) +{ + dump_restore(); +} + ################################################################## # Report PostGIS environment @@ -490,6 +497,8 @@ Options: -v, --verbose be verbose about failures --nocreate do not create the regression database on start --upgrade source the upgrade scripts on start + --upgrade-path upgrade path, format -- + --dumprestore dump and restore spatially-enabled db before running tests --nodrop do not drop the regression database on exit --raster load also raster extension --topology load also topology extension @@ -497,7 +506,6 @@ Options: --clean cleanup test logs on exit --expect save obtained output as expected --extension load using extensions - --upgrade-path upgrade path, format -- }; } @@ -1501,6 +1509,43 @@ sub uninstall_spatial return 0; } +# Dump and restore the database +sub dump_restore +{ + my $DBDUMP = $TMPDIR . '/' . $DB . ".dump"; + my $rv; + + print "Dumping and restoring database '${DB}'\n"; + + $rv = system("pg_dump -Fc ${DB} -f ${DBDUMP} >> $REGRESS_LOG 2>&1"); + if ( $rv ) { + fail("Could not dump ${DB}", $REGRESS_LOG); + die; + } + + $rv = system("dropdb ${DB} >> $REGRESS_LOG 2>&1"); + if ( $rv ) { + fail("Could not drop ${DB}", $REGRESS_LOG); + die; + } + + $rv = system("createdb ${DB} >> $REGRESS_LOG 2>&1"); + if ( $rv ) { + fail("Could not create ${DB}", $REGRESS_LOG); + die; + } + + $rv = system("pg_restore -d ${DB} ${DBDUMP} >> $REGRESS_LOG 2>&1"); + if ( $rv ) { + fail("Could not restore ${DB}", $REGRESS_LOG); + die; + }; + + unlink($DBDUMP); + + return 1; +} + sub diff { my ($expected_file, $obtained_file) = @_; -- 2.40.0