Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / 106dbic_carp.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 # without this the stacktrace of $schema will be activated
7 BEGIN { $ENV{DBIC_TRACE} = 0 }
8
9 use Test::More;
10 use Test::Warn;
11 use Test::Exception;
12
13 use DBICTest;
14 use DBIx::Class::Carp;
15
16 {
17   sub DBICTest::DBICCarp::frobnicate {
18     DBICTest::DBICCarp::branch1();
19     DBICTest::DBICCarp::branch2();
20   }
21
22   sub DBICTest::DBICCarp::branch1 { carp_once 'carp1' }
23   sub DBICTest::DBICCarp::branch2 { carp_once 'carp2' }
24
25
26   warnings_exist {
27     DBICTest::DBICCarp::frobnicate();
28   } [
29     qr/carp1/,
30     qr/carp2/,
31   ], 'expected warnings from carp_once';
32 }
33
34 {
35   {
36     package DBICTest::DBICCarp::Exempt;
37     use DBIx::Class::Carp;
38
39     sub _skip_namespace_frames { qr/^DBICTest::DBICCarp::Exempt/ }
40
41     sub thrower {
42       sub {
43         DBICTest->init_schema(no_deploy => 1)->storage->dbh_do(sub {
44           shift->throw_exception('time to die');
45         })
46       }->();
47     }
48
49     sub dcaller {
50       sub {
51         thrower();
52       }->();
53     }
54
55     sub warner {
56       eval {
57         sub {
58           eval {
59             carp ('time to warn')
60           }
61         }->()
62       }
63     }
64
65     sub wcaller {
66       warner();
67     }
68   }
69
70   # the __LINE__ relationship below is important - do not reformat
71   throws_ok { DBICTest::DBICCarp::Exempt::dcaller() }
72     qr/\QDBICTest::DBICCarp::Exempt::thrower(): time to die at @{[ __FILE__ ]} line @{[ __LINE__ - 1 ]}\E$/,
73     'Expected exception callsite and originator'
74   ;
75
76   # the __LINE__ relationship below is important - do not reformat
77   warnings_like { DBICTest::DBICCarp::Exempt::wcaller() }
78     qr/\QDBICTest::DBICCarp::Exempt::warner(): time to warn at @{[ __FILE__ ]} line @{[ __LINE__ - 1 ]}\E$/,
79   ;
80 }
81
82 done_testing;