X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=blobdiff_plain;f=t%2F34exception_action.t;h=e19ef1f9f3bad391235e6158b1db3ac265a81918;hp=0fec11a02763427d8b6862d3cce0a52534c8f6cd;hb=c3e9f7189094e94137356251c4f0b1f1cbfeb04a;hpb=68fe9141d8c2d8ca64a0bc6452b2ffbf36d28512 diff --git a/t/34exception_action.t b/t/34exception_action.t index 0fec11a..e19ef1f 100644 --- a/t/34exception_action.t +++ b/t/34exception_action.t @@ -2,6 +2,8 @@ use strict; use warnings; use Test::More; +use Test::Exception; +use Test::Warn; use lib qw(t/lib); use DBICTest; @@ -16,29 +18,42 @@ sub throwex { $schema->resultset("Artist")->search(1,1,1); } my $ex_regex = qr/Odd number of arguments to search/; # Basic check, normal exception -eval { throwex }; -my $e = $@; # like() seems to stringify $@ -like($@, $ex_regex); +throws_ok { throwex } + $ex_regex; + +my $e = $@; # Re-throw the exception with rethrow() -eval { $e->rethrow }; +throws_ok { $e->rethrow } + $ex_regex; isa_ok( $@, 'DBIx::Class::Exception' ); -like($@, $ex_regex); # Now lets rethrow via exception_action $schema->exception_action(sub { die @_ }); -eval { throwex }; -like($@, $ex_regex); +throws_ok { throwex } + $ex_regex; +# +# This should have never worked!!! +# # Now lets suppress the error $schema->exception_action(sub { 1 }); -eval { throwex }; -ok(!$@, "Suppress exception"); +throws_ok { throwex } + 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 }); -eval { throwex }; -like($@, $ex_regex); +throws_ok { + warnings_are { throwex } + qr/exception_action handler installed .+ returned false instead throwing an exception/; +} $ex_regex; + +# again to see if no warning +throws_ok { + warnings_are { throwex } + []; +} $ex_regex; + # Whacky useless exception class { @@ -60,12 +75,11 @@ like($@, $ex_regex); # Try the exception class $schema->exception_action(sub { DBICTest::Exception->throw(@_) }); -eval { throwex }; -like($@, qr/DBICTest::Exception is handling this: $ex_regex/); +throws_ok { throwex } + qr/DBICTest::Exception is handling this: $ex_regex/; # While we're at it, lets throw a custom exception through Storage::DBI -eval { $schema->storage->throw_exception('floob') }; -like($@, qr/DBICTest::Exception is handling this: floob/); - +throws_ok { $schema->storage->throw_exception('floob') } + qr/DBICTest::Exception is handling this: floob/; done_testing;