Test suite wide leaktesting
[dbsrgits/DBIx-Class.git] / t / 34exception_action.t
index e19ef1f..6de03f0 100644 (file)
@@ -14,12 +14,11 @@ my $schema = DBICTest->init_schema;
 #  which might need updating at some future time to be some other
 #  exception-generating statement:
 
-sub throwex { $schema->resultset("Artist")->search(1,1,1); }
+my $throw  = sub { $schema->resultset("Artist")->search(1,1,1) };
 my $ex_regex = qr/Odd number of arguments to search/;
 
 # Basic check, normal exception
-throws_ok { throwex }
-  $ex_regex;
+throws_ok \&$throw, $ex_regex;
 
 my $e = $@;
 
@@ -30,27 +29,26 @@ isa_ok( $@, 'DBIx::Class::Exception' );
 
 # Now lets rethrow via exception_action
 $schema->exception_action(sub { die @_ });
-throws_ok { throwex }
-  $ex_regex;
+throws_ok \&$throw, $ex_regex;
 
 #
 # This should have never worked!!!
 #
 # Now lets suppress the error
 $schema->exception_action(sub { 1 });
-throws_ok { throwex }
+throws_ok \&$throw,
   qr/exception_action handler .+ did \*not\* result in an exception.+original error: $ex_regex/;
 
 # Now lets fall through and let croak take back over
 $schema->exception_action(sub { return });
 throws_ok {
-  warnings_are { throwex }
+  warnings_are \&$throw,
     qr/exception_action handler installed .+ returned false instead throwing an exception/;
 } $ex_regex;
 
 # again to see if no warning
 throws_ok {
-  warnings_are { throwex }
+  warnings_are \&$throw,
     [];
 } $ex_regex;
 
@@ -75,7 +73,7 @@ throws_ok {
 
 # Try the exception class
 $schema->exception_action(sub { DBICTest::Exception->throw(@_) });
-throws_ok { throwex }
+throws_ok \&$throw,
   qr/DBICTest::Exception is handling this: $ex_regex/;
 
 # While we're at it, lets throw a custom exception through Storage::DBI