Use skip_all or diag for missing RDBMS test dependencies
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_09firebird_common.t
index 0dbbd11..65ce5c0 100644 (file)
@@ -2,16 +2,31 @@ use strict;
 use warnings;
 use Test::More;
 use Scope::Guard ();
+use DBIx::Class::Optional::Dependencies;
+use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/;
 use lib qw(t/lib);
 use dbixcsl_common_tests;
 
-my $dbd_interbase_dsn      = $ENV{DBICTEST_FIREBIRD_DSN} || '';
-my $dbd_interbase_user     = $ENV{DBICTEST_FIREBIRD_USER} || '';
-my $dbd_interbase_password = $ENV{DBICTEST_FIREBIRD_PASS} || '';
+my %dsns;
+for (qw(FIREBIRD FIREBIRD_ODBC FIREBIRD_INTERBASE)) {
+    next unless $ENV{"DBICTEST_${_}_DSN"};
 
-my $odbc_dsn      = $ENV{DBICTEST_FIREBIRD_ODBC_DSN} || '';
-my $odbc_user     = $ENV{DBICTEST_FIREBIRD_ODBC_USER} || '';
-my $odbc_password = $ENV{DBICTEST_FIREBIRD_ODBC_PASS} || '';
+    my $dep_group = lc "rdbms_$_";
+    if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) {
+        diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group)
+            . " to test with $_";
+        next;
+    }
+
+    $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"};
+    $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"};
+    $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"};
+    $dsns{$_}{connect_info_opts} = { on_connect_call => 'use_softcommit' }
+        if /\AFIREBIRD(?:_INTERBASE)\z/;
+};
+
+plan skip_all => 'You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_ODBC_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_INTERBASE_DSN, _USER and _PASS environment variables'
+    unless %dsns;
 
 my $schema;
 
@@ -43,19 +58,7 @@ my $tester = dbixcsl_common_tests->new(
     null        => '',
     preserve_case_mode_is_exclusive => 1,
     quote_char                      => '"',
-    warnings => [ qr/'preserve_case' option/ ],
-    connect_info => [ ($dbd_interbase_dsn ? {
-            dsn         => $dbd_interbase_dsn,
-            user        => $dbd_interbase_user,
-            password    => $dbd_interbase_password,
-            connect_info_opts => { on_connect_call => 'use_softcommit' },
-        } : ()),
-        ($odbc_dsn ? {
-            dsn         => $odbc_dsn,
-            user        => $odbc_user,
-            password    => $odbc_password,
-        } : ()),
-    ],
+    connect_info => [ values %dsns ],
     data_types  => {
         # based on the Interbase Data Definition Guide
         # http://www.ibphoenix.com/downloads/60DataDef.zip
@@ -109,7 +112,6 @@ my $tester = dbixcsl_common_tests->new(
         'varchar(33) character set unicode_fss' =>
                        => { data_type => 'varchar(x) character set unicode_fss', size => 33 },
 
-
         # Blob types
         'blob'        => { data_type => 'blob' },
         'blob sub_type text'
@@ -151,8 +153,8 @@ q{
 
             my $guard = Scope::Guard->new(\&cleanup_extra);
 
-            local $schema->_loader->{preserve_case} = 1;
-            $schema->_loader->_setup;
+            local $schema->loader->{preserve_case} = 1;
+            $schema->loader->_setup;
 
             $self->rescan_without_warnings($schema);
 
@@ -179,7 +181,7 @@ q{
                 );
 
                 for my $type_num (keys %truncated_types) {
-                    is $schema->_loader->_dbh_type_info_type_name($type_num),
+                    is $schema->loader->_dbh_type_info_type_name($type_num),
                         $truncated_types{$type_num},
                         "ODBC ->_dbh_type_info_type_name correct for '$truncated_types{$type_num}'";
                 }
@@ -192,17 +194,16 @@ q{
     },
 );
 
-if (not ($dbd_interbase_dsn || $odbc_dsn)) {
-    $tester->skip_tests('You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_ODBC_DSN, _USER and _PASS environment variables');
-}
-else {
+{
     # get rid of stupid warning from InterBase/GetInfo.pm
-    if ($dbd_interbase_dsn) {
-        local $SIG{__WARN__} = sub { warn @_
-            unless $_[0] =~ m|^Use of uninitialized value in sprintf at \S+DBD/InterBase/GetInfo\.pm line \d+\.$| };
+    if ($dsns{FIREBIRD_INTERBASE}) {
+        local $SIG{__WARN__} = sigwarn_silencer(
+            qr{^Use of uninitialized value in sprintf at \S+DBD/InterBase/GetInfo\.pm line \d+\.$|^Missing argument in sprintf at \S+DBD/InterBase/GetInfo.pm line \d+\.$}
+        );
         require DBD::InterBase;
         require DBD::InterBase::GetInfo;
     }
+
     $tester->run_tests();
 }