Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / t / 33exception_wrap.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
c6d30d5e 3use strict;
4use warnings;
5
6use Test::More;
7use Test::Exception;
84e4e006 8use Test::Warn;
c6d30d5e 9
c6d30d5e 10use DBICTest;
11my $schema = DBICTest->init_schema;
12
13throws_ok (sub {
14 $schema->txn_do (sub { die 'lol' } );
15}, 'DBIx::Class::Exception', 'a DBIC::Exception object thrown');
16
17throws_ok (sub {
18 $schema->txn_do (sub { die [qw/lol wut/] });
19}, qr/ARRAY\(0x/, 'An arrayref thrown');
20
21is_deeply (
22 $@,
23 [qw/ lol wut /],
24 'Exception-arrayref contents preserved',
25);
26
84e4e006 27for my $ap (qw(
28 DBICTest::AntiPattern::TrueZeroLen
29 DBICTest::AntiPattern::NullObject
30)) {
31 eval "require $ap";
32
33 warnings_like {
34 eval {
35 $schema->txn_do (sub { die $ap->new });
36 };
37
38 isa_ok $@, $ap;
39 } qr/\QObjects of external exception class '$ap' stringify to '' (the empty string)/,
40 'Proper warning on encountered antipattern';
35cf7d1a 41
42 warnings_are {
43 $@ = $ap->new;
44 $schema->txn_do (sub { 1 });
45
46 $@ = $ap->new;
47 $schema->txn_scope_guard->commit;
48 } [], 'No spurious PSA warnings on pre-existing antipatterns in $@';
49
84e4e006 50}
51
c6d30d5e 52done_testing;