Some cosmetic fixes in ANFANG
[dbsrgits/DBIx-Class.git] / t / 106dbic_carp.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
8fda97d5 3use strict;
4use warnings;
5
5e0e5426 6# without this the stacktrace of $schema will be activated
7BEGIN { $ENV{DBIC_TRACE} = 0 }
8
8fda97d5 9use Test::More;
10use Test::Warn;
5e0e5426 11use Test::Exception;
c0329273 12
8fda97d5 13use DBICTest;
5e724964 14use DBIx::Class::Carp;
8fda97d5 15
5e0e5426 16{
17 sub DBICTest::DBICCarp::frobnicate {
18 DBICTest::DBICCarp::branch1();
19 DBICTest::DBICCarp::branch2();
20 }
8fda97d5 21
5e0e5426 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;
8fda97d5 38
5e0e5426 39 sub _skip_namespace_frames { qr/^DBICTest::DBICCarp::Exempt/ }
40
41 sub thrower {
42 sub {
cc414f09 43 DBICTest->init_schema(no_deploy => 1)->storage->dbh_do(sub {
44 shift->throw_exception('time to die');
45 })
5e0e5426 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 ;
8fda97d5 80}
81
5e0e5426 82done_testing;