edd8a4efa51fcd413bb017e4e77a0a76af113315
[p5sagit/Try-Tiny.git] / t / given_when.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9   plan skip_all => "Perl 5.10 is required" unless eval { require 5.010 };
10   plan tests => 3;
11   use_ok("Try::Tiny");
12 }
13
14 use 5.010;
15 no if $] >= 5.017011, warnings => 'experimental::smartmatch';
16
17 my ( $error, $topic );
18
19 given ("foo") {
20   when (qr/./) {
21     try {
22       die "blah\n";
23     } catch {
24       $topic = $_;
25       $error = $_[0];
26     }
27   };
28 }
29
30 is( $error, "blah\n", "error caught" );
31
32 {
33   local $TODO = "perhaps a workaround can be found"
34     if $] < 5.017003;
35   is( $topic, $error, 'error is also in $_' );
36 }
37
38 # ex: set sw=4 et:
39