Fix TxnScopeGuard misbehaving on externally set $@ without inner exceptions
[dbsrgits/DBIx-Class.git] / t / storage / txn_scope_guard.t
index f79ff8d..739ed6c 100644 (file)
@@ -92,7 +92,9 @@ use DBICTest;
 
   no strict 'refs';
   no warnings 'redefine';
+
   local *{DBIx::Class::Storage::DBI::txn_rollback} = sub { die 'die die my darling' };
+  Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO;
 
   throws_ok (sub {
     my $guard = $schema->txn_scope_guard;
@@ -114,12 +116,15 @@ use DBICTest;
 }
 
 # make sure it warns *big* on failed rollbacks
-{
+# test with and without a poisoned $@
+for my $poison (0,1) {
+
   my $schema = DBICTest->init_schema();
 
   no strict 'refs';
   no warnings 'redefine';
   local *{DBIx::Class::Storage::DBI::txn_rollback} = sub { die 'die die my darling' };
+  Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO;
 
 #The warn from within a DESTROY callback freaks out Test::Warn, do it old-school
 =begin
@@ -157,11 +162,12 @@ use DBICTest;
     }
   };
   {
+      eval { die 'GIFT!' if $poison };
       my $guard = $schema->txn_scope_guard;
       $schema->resultset ('Artist')->create ({ name => 'bohhoo'});
   }
 
-  is (@w, 2, 'Both expected warnings found');
+  is (@w, 2, 'Both expected warnings found' . ($poison ? ' (after $@ poisoning)' : '') );
 
   # just to mask off warning since we could not disconnect above
   $schema->storage->_dbh->disconnect;