Fix building on perls with no . in @INC
[dbsrgits/DBIx-Class.git] / t / 33exception_wrap.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8 use Test::Warn;
9
10 use DBICTest;
11 my $schema = DBICTest->init_schema;
12
13 throws_ok (sub {
14   $schema->txn_do (sub { die 'lol' } );
15 }, 'DBIx::Class::Exception', 'a DBIC::Exception object thrown');
16
17 throws_ok (sub {
18   $schema->txn_do (sub { die [qw/lol wut/] });
19 }, qr/ARRAY\(0x/, 'An arrayref thrown');
20
21 is_deeply (
22   $@,
23   [qw/ lol wut /],
24   'Exception-arrayref contents preserved',
25 );
26
27 for 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';
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
50 }
51
52 done_testing;