just skip when tests on all perls since when changed to whereis/whereso
[p5sagit/Try-Tiny.git] / t / 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+, pending resolution of smartmatch changes' if "$]" >= '5.027007';
9   plan tests => 5;
10 }
11
12 use Try::Tiny;
13
14 use 5.010;
15 no if "$]" >= 5.017011, warnings => 'experimental::smartmatch';
16
17 my ( $foo, $bar, $other );
18
19 $_ = "magic";
20
21 try {
22   die "foo";
23 } catch {
24
25   like( $_, qr/foo/ );
26
27   when (/bar/) { $bar++ };
28   when (/foo/) { $foo++ };
29   default { $other++ };
30 };
31
32 is( $_, "magic", '$_ not clobbered' );
33
34 ok( !$bar, "bar didn't match" );
35 ok( $foo, "foo matched" );
36 ok( !$other, "fallback didn't match" );