1use Test2::Bundle::Extended -target => 'Test2::Tools::Exception';
2
3{
4    package Foo;
5    use Test2::Tools::Exception qw/dies lives try_ok/;
6    ::imported_ok(qw/dies lives try_ok/);
7}
8
9use Test2::API qw/intercept/;
10
11like(
12    dies { die 'xyz' },
13    qr/xyz/,
14    "Got exception"
15);
16
17is(dies { 0 }, undef, "no exception");
18
19{
20    local $@ = 'foo';
21    ok(lives { 0 }, "it lives!");
22    is($@, "foo", "did not change \$@");
23}
24
25ok(!lives { die 'xxx' }, "it died");
26like($@, qr/xxx/, "Exception is available");
27
28try_ok { 0 } "No Exception from try_ok";
29
30my $err;
31is(
32    intercept { try_ok { die 'abc' } "foo"; $err = $@; },
33    array {
34        fail_events Ok => sub {
35            call name => "foo";
36            call pass => 0;
37        };
38        event Diag => sub { msg => match qr/abc/; };
39    },
40    "Got failure + diag from try_ok"
41);
42
43like($err, qr/abc/, '$@ has the exception');
44
45done_testing;
46