X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F58-yield-misc.t;h=2eb222ff8e6c07a11715ff57bba2f9b2de2f2a63;hb=be1d59463692da1b5ef787aeffd0aedbef65664e;hp=23fc1d4967fc696dd1fcde037886db0ec52cc183;hpb=1cac52223ba0983d5d4007ab608fe4ea645eb037;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/58-yield-misc.t b/t/58-yield-misc.t index 23fc1d4..2eb222f 100644 --- a/t/58-yield-misc.t +++ b/t/58-yield-misc.t @@ -3,12 +3,12 @@ use strict; use warnings; -use Test::More tests => 4 * 3; +use Test::More tests => 4 * 3 + 3; use lib 't/lib'; use VPIT::TestHelpers; -use Scope::Upper qw; +use Scope::Upper qw; # Test timely destruction of values returned from yield() @@ -74,3 +74,34 @@ sub guard { VPIT::TestHelpers::Guard->new(sub { ++$destroyed }) } } is $destroyed, 1, "$desc: destroyed 2"; } + +# Test leave + +{ + my @res = (1, do { + leave; + 'XXX'; + }, 2); + is "@res", '1 2', 'leave without arguments'; +} + +{ + my @res = (1, do { + leave 2, 3; + 'XXX'; + }, 4); + is "@res", '1 2 3 4', 'leave with arguments'; +} + +{ + my $s = 'a'; + local $@; + eval { + $s =~ s/./leave; die 'not reached'/e; + }; + my $err = $@; + my $line = __LINE__-3; + like $err, + qr/^leave\(\) cannot target a substitution context at \Q$0\E line $line/, + 'leave() cannot exit subst'; +}