Fix missing handling of on_(dis)connect* failures
[dbsrgits/DBIx-Class-Historic.git] / t / admin / 02ddl.t
index 8b1c57f..b2414c3 100644 (file)
@@ -1,3 +1,5 @@
+use DBIx::Class::Optional::Dependencies -skip_all_without => qw( admin deploy );
+
 use strict;
 use warnings;
 
@@ -9,17 +11,9 @@ use Path::Class;
 
 use lib qw(t/lib);
 use DBICTest;
+use DBIx::Class::_Util 'sigwarn_silencer';
 
-BEGIN {
-    require DBIx::Class;
-    plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('admin')
-      unless DBIx::Class::Optional::Dependencies->req_ok_for('admin');
-
-    plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
-      unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
-}
-
-use_ok 'DBIx::Class::Admin';
+use DBIx::Class::Admin;
 
 # lock early
 DBICTest->init_schema(no_deploy => 1, no_populate => 1);
@@ -48,7 +42,7 @@ isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
 lives_ok {
-  $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s };
+  local $SIG{__WARN__} = sigwarn_silencer( qr/no such table.+DROP TABLE/s );
   $admin->deploy()
 } 'Can Deploy schema';
 }
@@ -86,9 +80,9 @@ $admin = DBIx::Class::Admin->new(
 
 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
 {
-  local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DB version .+? is lower than the schema version/ };
-  lives_ok {$admin->upgrade();} 'upgrade the schema';
-  dies_ok {$admin->deploy} 'cannot deploy installed schema, should upgrade instead';
+  local $SIG{__WARN__} = sigwarn_silencer( qr/DB version .+? is lower than the schema version/ );
+  lives_ok { $admin->upgrade() } 'upgrade the schema';
+  dies_ok { $admin->deploy } 'cannot deploy installed schema, should upgrade instead';
 }
 
 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
@@ -107,13 +101,15 @@ my $admin = DBIx::Class::Admin->new(
 );
 
 $admin->version("3.0");
-lives_ok { $admin->install(); } 'install schema version 3.0';
+$admin->install;
 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
-dies_ok { $admin->install("4.0"); } 'cannot install to allready existing version';
+throws_ok {
+  $admin->install("4.0")
+} qr/Schema already has a version. Try upgrade instead/, 'cannot install to allready existing version';
 
 $admin->force(1);
 warnings_exist ( sub {
-  lives_ok { $admin->install("4.0") } 'can force install to allready existing version'
+  $admin->install("4.0")
 }, qr/Forcing install may not be a good idea/, 'Force warning emitted' );
 is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
 }