fix warning, fix test counts
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / lib / dbixcsl_common_tests.pm
index 40e8da8..dc10b92 100644 (file)
@@ -26,6 +26,9 @@ rmtree $DUMP_DIR;
 
 use constant RESCAN_WARNINGS => qr/(?i:loader_test|LoaderTest)\d+s? has no primary key|^Dumping manual schema|^Schema dump completed|collides with an inherited method|invalidates \d+ active statement|^Bad table or view/;
 
+# skip schema-qualified tables in the Pg tests
+use constant SOURCE_DDL => qr/CREATE (?:TABLE|VIEW) (?!"dbicsl[.-]test")/i;
+
 sub new {
     my $class = shift;
 
@@ -104,12 +107,11 @@ sub run_tests {
 
     my $col_accessor_map_tests = 5;
     my $num_rescans = 5;
-    $num_rescans-- if $self->{vendor} eq 'Mysql';
     $num_rescans++ if $self->{vendor} eq 'mssql';
     $num_rescans++ if $self->{vendor} eq 'Firebird';
 
     plan tests => @connect_info *
-        (203 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0));
+        (203 + ($self->{skip_rels} ? 5 : $num_rescans * $col_accessor_map_tests) + $extra_count + ($self->{data_type_tests}{test_count} || 0));
 
     foreach my $info_idx (0..$#connect_info) {
         my $info = $connect_info[$info_idx];
@@ -150,7 +152,7 @@ sub run_only_extra_tests {
 
         $self->{_created} = 1;
 
-        my $file_count = grep /CREATE (?:TABLE|VIEW)/i, @{ $self->{extra}{create} || [] };
+        my $file_count = grep $_ =~ SOURCE_DDL, @{ $self->{extra}{create} || [] };
         $file_count++; # schema
         
         if (not ($self->{vendor} eq 'mssql' && $dbh->{Driver}{Name} eq 'Sybase')) {
@@ -211,7 +213,7 @@ sub setup_schema {
 
     my %loader_opts = (
         constraint              =>
-          qr/^(?:\S+\.)?(?:(?:$self->{vendor}|extra)_?)?loader_?test[0-9]+(?!.*_)/i,
+          qr/^(?:\S+\.)?(?:(?:$self->{vendor}|extra)[_-]?)?loader[_-]?test[0-9]+(?!.*_)/i,
         relationships           => 1,
         additional_classes      => 'TestAdditional',
         additional_base_classes => 'TestAdditionalBase',
@@ -267,7 +269,7 @@ sub setup_schema {
                 $expected_count++ for @{ $self->{data_type_tests}{table_names} || [] };
             }
 
-            $expected_count += grep /CREATE (?:TABLE|VIEW)/i,
+            $expected_count += grep $_ =~ SOURCE_DDL,
                 @{ $self->{extra}{create} || [] };
      
             $expected_count -= grep /CREATE TABLE/, @statements_inline_rels
@@ -308,7 +310,7 @@ sub setup_schema {
             }
             else {
                 $warn_count++;
-                is(scalar(@loader_warnings), $warn_count, "Expected loader warning")
+                is(scalar(@loader_warnings), $warn_count, "Expected loader warnings")
                     or diag @loader_warnings;
                 is(grep(/loader_test9 has no primary key/i, @loader_warnings), 1,
                      "Missing PK warning");
@@ -563,7 +565,7 @@ sub test_schema {
     }
 
     SKIP: {
-        skip $self->{skip_rels}, 124 if $self->{skip_rels};
+        skip $self->{skip_rels}, 132 if $self->{skip_rels};
 
         my $moniker3 = $monikers->{loader_test3};
         my $class3   = $classes->{loader_test3};
@@ -966,7 +968,7 @@ qr/\n__PACKAGE__->(?:belongs_to|has_many|might_have|has_one|many_to_many)\(
         }
 
         SKIP: {
-            skip 'This vendor cannot do inline relationship definitions', 11
+            skip 'This vendor cannot do inline relationship definitions', 9
                 if $self->{no_inline_rels};
 
             my $moniker12 = $monikers->{loader_test12};
@@ -991,35 +993,36 @@ qr/\n__PACKAGE__->(?:belongs_to|has_many|might_have|has_one|many_to_many)\(
 
             my $obj12 = try { $rsobj12->find(1) } || $rsobj12->search({ id => 1 })->first;
             isa_ok( try { $obj12->loader_test13 }, $class13 );
+        }
 
-            # relname is preserved when another fk is added
-
-            {
-                local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /invalidates \d+ active statement/ };
-                $conn->storage->disconnect; # for mssql and access
-            }
+        # relname is preserved when another fk is added
+        {
+            local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /invalidates \d+ active statement/ };
+            $conn->storage->disconnect; # for mssql and access
+        }
 
-            isa_ok try { $rsobj3->find(1)->loader_test4zes }, 'DBIx::Class::ResultSet';
+        isa_ok try { $rsobj3->find(1)->loader_test4zes }, 'DBIx::Class::ResultSet';
 
-            $conn->storage->disconnect; # for access
+        $conn->storage->disconnect; # for access
 
-            if (lc($self->{vendor}) ne 'sybase') {
-                $conn->storage->dbh->do('ALTER TABLE loader_test4 ADD fkid2 INTEGER REFERENCES loader_test3 (id)');
-            }
-            else {
-                $conn->storage->dbh->do(<<"EOF");
-                ALTER TABLE loader_test4 ADD fkid2 INTEGER $self->{null}
-                ALTER TABLE loader_test4 ADD CONSTRAINT loader_test4_to_3_fk FOREIGN KEY (fkid2) REFERENCES loader_test3 (id)
+        if (lc($self->{vendor}) !~ /^(?:sybase|mysql)\z/) {
+            $conn->storage->dbh->do('ALTER TABLE loader_test4 ADD fkid2 INTEGER REFERENCES loader_test3 (id)');
+        }
+        else {
+            $conn->storage->dbh->do(<<"EOF");
+            ALTER TABLE loader_test4 ADD fkid2 INTEGER $self->{null}
 EOF
-            }
+            $conn->storage->dbh->do(<<"EOF");
+            ALTER TABLE loader_test4 ADD CONSTRAINT loader_test4_to_3_fk FOREIGN KEY (fkid2) REFERENCES loader_test3 (id)
+EOF
+        }
 
-            $conn->storage->disconnect; # for firebird
+        $conn->storage->disconnect; # for firebird
 
-            $self->rescan_without_warnings($conn);
+        $self->rescan_without_warnings($conn);
 
-            isa_ok try { $rsobj3->find(1)->loader_test4zes }, 'DBIx::Class::ResultSet',
-                'relationship name preserved when another foreign key is added in remote table';
-        }
+        isa_ok try { $rsobj3->find(1)->loader_test4zes }, 'DBIx::Class::ResultSet',
+            'relationship name preserved when another foreign key is added in remote table';
 
         SKIP: {
             skip 'This vendor cannot do out-of-line implicit rel defs', 4
@@ -1819,7 +1822,7 @@ sub create {
         $dbh->do($_) foreach (@{ $self->{data_type_tests}{ddl} || [] });
     }
 
-    unless($self->{skip_rels}) {
+    unless ($self->{skip_rels}) {
         # hack for now, since DB2 doesn't like inline comments, and we need
         # to test one for mysql, which works on everyone else...
         # this all needs to be refactored anyways.
@@ -1944,7 +1947,7 @@ sub drop_tables {
 
         my $drop_auto_inc = $self->{auto_inc_drop_cb} || sub {};
 
-        unless($self->{skip_rels}) {
+        unless ($self->{skip_rels}) {
             # drop the circular rel columns if possible, this
             # doesn't work on all DBs
             foreach my $table (keys %drop_columns) {