6 use Test::More tests => 4 * 3 + 3;
11 use Scope::Upper qw<yield leave HERE>;
13 # Test timely destruction of values returned from yield()
16 sub guard { VPIT::TestHelpers::Guard->new(sub { ++$destroyed }) }
19 my $desc = 'scalar context, above';
24 is $destroyed, undef, "$desc: not yet destroyed 1";
28 is $destroyed, undef, "$desc: not yet destroyed 2";
30 is $destroyed, 1, "$desc: destroyed 1";
34 my $desc = 'scalar context, below';
39 is $destroyed, undef, "$desc: not yet destroyed 1";
43 is $destroyed, undef, "$desc: not yet destroyed 2";
45 is $destroyed, 1, "$desc: destroyed 1";
49 my $desc = 'void context, above';
54 is $destroyed, undef, "$desc: not yet destroyed 1";
58 is $destroyed, undef, "$desc: not yet destroyed 2";
60 is $destroyed, 1, "$desc: destroyed 1";
64 my $desc = 'void context, below';
68 is $destroyed, undef, "$desc: not yet destroyed 1";
73 is $destroyed, 1, "$desc: destroyed 1";
75 is $destroyed, 1, "$desc: destroyed 2";
85 is "@res", '1 2', 'leave without arguments';
93 is "@res", '1 2 3 4', 'leave with arguments';
100 $s =~ s/./leave; die 'not reached'/e;
103 my $line = __LINE__-3;
105 qr/^leave\(\) cannot target a substitution context at \Q$0\E line $line/,
106 'leave() cannot exit subst';