Use skip_all or diag for missing RDBMS test dependencies
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_10informix_common.t
index e2f77c9..e8b6b58 100644 (file)
@@ -4,6 +4,7 @@ use Test::More;
 use Test::Exception;
 use Try::Tiny;
 use File::Path 'rmtree';
+use DBIx::Class::Optional::Dependencies;
 use DBIx::Class::Schema::Loader 'make_schema_at';
 use DBIx::Class::Schema::Loader::Utils 'split_name';
 use String::ToIdentifier::EN::Unicode 'to_identifier';
@@ -144,7 +145,6 @@ my $tester = dbixcsl_common_tests->new(
                 });
 
                 my $dbh1 = $schema->storage->dbh;
-                my $dbh2 = $extra_schema->storage->dbh;
 
                 $dbh1->do(<<'EOF');
                     CREATE TABLE informix_loader_test4 (
@@ -162,6 +162,13 @@ EOF
                 $dbh1->do(<<'EOF');
 ALTER TABLE informix_loader_test5 ADD CONSTRAINT UNIQUE (four_id) CONSTRAINT loader_test5_uniq
 EOF
+
+                my $db1 = db_name($schema);
+
+                $dbh1->disconnect;
+
+                my $dbh2 = $extra_schema->storage->dbh;
+
                 $dbh2->do(<<'EOF');
                     CREATE TABLE informix_loader_test5 (
                         pk SERIAL PRIMARY KEY,
@@ -186,9 +193,10 @@ EOF
                     )
 EOF
 
-                my $db1 = db_name($schema);
                 my $db2 = db_name($extra_schema);
 
+                $dbh2->disconnect;
+
                 my $db1_moniker = join '', map ucfirst lc, split_name to_identifier $db1;
                 my $db2_moniker = join '', map ucfirst lc, split_name to_identifier $db2;
 
@@ -211,6 +219,8 @@ EOF
                             [ $dsn, $user, $password ],
                         );
 
+                        InformixMultiDatabase->storage->disconnect;
+
                         diag join "\n", @warns if @warns;
 
                         is @warns, 0;
@@ -326,6 +336,9 @@ EOF
 if( !$dsn ) {
     $tester->skip_tests('You need to set the DBICTEST_INFORMIX_DSN, _USER, and _PASS environment variables');
 }
+elsif (!DBIx::Class::Optional::Dependencies->req_ok_for ('rdbms_informix')) {
+    $tester->skip_tests('You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for ('rdbms_informix'));
+}
 else {
     $tester->run_tests();
 }
@@ -338,23 +351,37 @@ sub db_name {
     local $schema->loader->{schema} = $schema;
 
     return $schema->loader->_current_db;
+
+    $schema->storage->disconnect;
 }
 
 END {
     if (not $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) {
         if (my $dbh2 = try { $extra_schema->storage->dbh }) {
-            my $dbh1 = $schema->storage->dbh;
 
             try {
                 $dbh2->do('DROP TABLE informix_loader_test7');
                 $dbh2->do('DROP TABLE informix_loader_test6');
                 $dbh2->do('DROP TABLE informix_loader_test5');
+            }
+            catch {
+                die "Error dropping test tables: $_";
+            };
+
+            $dbh2->disconnect;
+        }
+
+        if (my $dbh1 = try { $schema->storage->dbh }) {
+            
+            try {
                 $dbh1->do('DROP TABLE informix_loader_test5');
                 $dbh1->do('DROP TABLE informix_loader_test4');
             }
             catch {
                 die "Error dropping test tables: $_";
             };
+
+            $dbh1->disconnect;
         }
 
         rmtree EXTRA_DUMP_DIR;