better table membership test
authorJason Etheridge <jason@esilibrary.com>
Wed, 24 Jul 2013 20:11:19 +0000 (16:11 -0400)
committerJason Etheridge <jason@esilibrary.com>
Wed, 24 Jul 2013 20:11:19 +0000 (16:11 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/sql/Pg/make-pgtap-tests.pl

index cc3ffb9..cd1ef86 100755 (executable)
@@ -192,12 +192,22 @@ sub handle_tables {
     my $callback = shift;
 
     my @tables = fetch_tables($schema);
+    if (scalar @tables == 0) {
+        return;
+    }
+
+    print "SELECT tables_are(\n";
+    print "\t" . $dbh->quote($schema) . ",\n";
+    print "\tARRAY[\n\t\t";
+    print join(
+        ",\n\t\t",
+        map { $dbh->quote($_) } @tables
+    );
+    print "\n\t],\t" . $dbh->quote("Found expected tables for schema $schema");
+    print "\n);\n";
+
     foreach my $table ( @tables ) {
         print "\n-- -- table " . $dbh->quote("$schema.$table") . "\n\n";
-        print "SELECT has_table(\n";
-        print "\t" . $dbh->quote($schema) . ",\n";
-        print "\t" . $dbh->quote($table) . ",\n";
-        print "\t" . $dbh->quote("Has table $schema.$table") . "\n);\n";
         $callback->($schema,$table) if $callback;
     }
 }