1#! perl 2 3use strict; 4use warnings; 5 6use Test::More 0.89; 7 8plan skip_all => 'This module is a no-op on perls earlier than 5.010' if "$]" < 5.010000; 9 10local $SIG{__WARN__} = sub { fail("Got unexpected warning"); diag($_[0]) }; 11 12if ($] >= 5.010000) { 13 is (eval <<'END', 1, 'state compiles') or diag $@; 14 use experimental 'state'; 15 state $foo = 1; 16 is($foo, 1, '$foo is 1'); 17 1; 18END 19} 20 21use warnings (); 22if ( $] >= 5.010001 23 && ( $] < 5.017011 || exists $warnings::Offsets{"experimental::smartmatch"} ) ) { 24 is (eval <<'END', 1, 'switch compiles') or diag $@; 25 use experimental 'switch'; 26 sub bar { 1 }; 27 given(1) { 28 when (\&bar) { 29 pass("bar matches 1"); 30 } 31 default { 32 fail("bar matches 1"); 33 } 34 } 35 1; 36END 37} 38 39if ( $] >= 5.010001 40 && ( $] < 5.017011 || exists $warnings::Offsets{"experimental::smartmatch"} ) ) { 41 is (eval <<'END', 1, 'smartmatch compiles') or diag $@; 42 use experimental 'smartmatch'; 43 sub baz { 1 }; 44 is(1 ~~ \&baz, 1, "is 1"); 45 1; 46END 47} 48 49if ($] >= 5.018) { 50 is (eval <<'END', 1, 'lexical subs compiles') or diag $@; 51 use experimental 'lexical_subs'; 52 my sub foo { 1 }; 53 is(foo(), 1, "foo is 1"); 54 1; 55END 56} 57 58if ($] >= 5.026000) { 59 is (eval <<'END', 1, 'declared refs compiles') or diag $@; 60 use experimental 'declared_refs'; 61 my @b; 62 my \@a = \@b; 63 is(\@a, \@b, '@a and @b are the same after \@a=\@b'); 64 1; 65END 66} 67elsif ($] >= 5.021005) { 68 is (eval <<'END', 1, 'ref aliasing compiles') or diag $@; 69 use experimental 'refaliasing'; 70 my (@a, @b); 71 \@a = \@b; 72 is(\@a, \@b, '@a and @b are the same after \@a=\@b'); 73 1; 74END 75} 76 77done_testing; 78 79