]> granicus.if.org Git - postgis/commitdiff
Add --dumprestore switch to ./run_test.pl
authorSandro Santilli <strk@keybit.net>
Tue, 9 Feb 2016 15:47:59 +0000 (15:47 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 9 Feb 2016 15:47:59 +0000 (15:47 +0000)
See #3444

git-svn-id: http://svn.osgeo.org/postgis/trunk@14651 b70326c6-7e19-0410-871a-916f4a2858ee

regress/run_test.pl

index aa1944e25b94c2430d5aacb1d7093c7beec5f31c..cf49b49634c57becc3abf55b1091cc401e42596c 100755 (executable)
@@ -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 <from>--<to>
+  --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 <from>--<to>
 };
 
 }
@@ -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) = @_;