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