32fb83c4b74fdd3f2c1d7bd5a7c2202f6fd0145d
[p5sagit/Try-Tiny.git] / t / named.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9         plan skip_all => "Sub::Name required"
10                 unless eval { require Sub::Name; 1 };
11         plan tests => 4;
12 }
13
14 BEGIN { use_ok 'Try::Tiny' }
15
16 my $name;
17 try {
18         $name = (caller(0))[3];
19 };
20 is $name, "main::try {...} ", "try name"; # note extra space
21
22 try {
23         die "Boom";
24 } catch {
25         $name = (caller(0))[3];
26 };
27 is $name, "main::catch {...} ", "catch name"; # note extra space
28
29 try {
30         die "Boom";
31 } catch {
32         # noop
33 } finally {
34         $name = (caller(0))[3];
35 };
36 is $name, "main::finally {...} ", "finally name"; # note extra space
37