6 use Test::More tests => 38 + 30 + 4 * 7;
8 use Scope::Upper qw/reap UP HERE/;
21 is $x, 2, 'goto 1 [not yet - x]';
22 is $y, undef, 'goto 1 [not yet - y]';
30 is $x, 1, 'goto 1 [ok - x]';
31 is $y, 1, 'goto 1 [ok - y]';
42 reap \&check => UP UP;
44 is $x, 3, 'goto 2 [not yet - x]';
45 is $y, undef, 'goto 2 [not yet - y]';
54 is $x, 1, 'goto 2 [ok - x]';
55 is $y, 1, 'goto 2 [ok - y]';
67 reap \&check => UP UP UP;
68 is $x, 3, 'die - reap outside eval [not yet 1 - x]';
69 is $y, undef, 'die - reap outside eval [not yet 1 - y]';
71 is $x, 2, 'die - reap outside eval [not yet 2 - x]';
72 is $y, undef, 'die - reap outside eval [not yet 2 - y]';
76 is $x, 1, 'die - reap outside eval [not yet 3 - x]';
77 is $y, undef, 'die - reap outside eval [not yet 3 - y]';
78 } # should trigger here
79 is $x, 1, 'die - reap outside eval [ok - x]';
80 is $y, 1, 'die - reap outside eval [ok - y]';
91 reap \&check => UP UP;
92 is $x, 3, 'die - reap at eval [not yet 1 - x]';
93 is $y, undef, 'die - reap at eval [not yet 1 - y]';
95 is $x, 2, 'die - reap at eval [not yet 2 - x]';
96 is $y, undef, 'die - reap at eval [not yet 2 - y]';
99 }; # should trigger here
100 is $x, 1, 'die - reap at eval [ok - x]';
101 is $y, 1, 'die - reap at eval [ok - y]';
113 is $x, 3, 'die - reap inside eval [not yet 1 - x]';
114 is $y, undef, 'die - reap inside eval [not yet 1 - y]';
116 is $x, 2, 'die - reap inside eval [not yet 2 - x]';
117 is $y, undef, 'die - reap inside eval [not yet 2 - y]';
119 } # should trigger here
121 is $x, 1, 'die - reap inside eval [ok - x]';
122 is $y, 1, 'die - reap inside eval [ok - y]';
127 skip 'Perl 5.10 required to test given/when' => 30 if $] < 5.010;
129 eval <<' GIVEN_TEST_1';
130 use feature 'switch';
139 is $x, 3, 'given/when - reap at given [not yet - x]';
140 is $y, undef, 'given/when - reap at given [not yet - y]';
144 is $x, 1, 'given/when - reap at given [ok - x]';
145 is $y, 1, 'given/when - reap at given [ok - y]';
150 eval <<' GIVEN_TEST_2';
151 use feature 'switch';
160 is $x, 3, 'given/when/continue - reap at given [not yet 1 - x]';
161 is $y, undef, 'given/when/continue - reap at given [not yet 1 - y]';
164 is $x, 2, 'given/when/continue - reap at given [not yet 2 - x]';
165 is $y, undef, 'given/when/continue - reap at given [not yet 2 - y]';
167 is $x, 1, 'given/when/continue - reap at given [ok - x]';
168 is $y, 1, 'given/when/continue - reap at given [ok - y]';
173 eval <<' GIVEN_TEST_3';
174 use feature 'switch';
183 is $x, 3, 'given/default - reap at given [not yet - x]';
184 is $y, undef, 'given/default - reap at given [not yet - y]';
188 is $x, 1, 'given/default - reap at given [ok - x]';
189 is $y, 1, 'given/default - reap at given [ok - y]';
194 eval <<' GIVEN_TEST_4';
195 use feature 'switch';
204 is $x, 3, 'given/default/continue - reap at given [not yet 1 - x]';
205 is $y, undef, 'given/default/continue - reap at given [not yet 1 - y]';
208 is $x, 2, 'given/default/continue - reap at given [not yet 2 - x]';
209 is $y, undef, 'given/default/continue - reap at given [not yet 2 - y]';
211 is $x, 1, 'given/default/continue - reap at given [ok - x]';
212 is $y, 1, 'given/default/continue - reap at given [ok - y]';
217 eval <<' GIVEN_TEST_5';
218 use feature 'switch';
230 reap \&check => UP UP;
231 is $x, 5, 'given/default/given/when - reap at default [not yet 1 - x]';
232 is $y, undef, 'given/default/given/when - reap at default [not yet 1 - y]';
235 is $x, 4, 'given/default/given/when - reap at default [not yet 2 - x]';
236 is $y, undef, 'given/default/given/when - reap at default [not yet 2 - y]';
238 is $x, 3, 'given/default/given/when - reap at default [not yet 3 - x]';
239 is $y, undef, 'given/default/given/when - reap at default [not yet 3 - y]';
242 is $x, 2, 'given/default/given/when - reap at default [ok 1 - x]';
243 is $y, 1, 'given/default/given/when - reap at default [ok 1 - y]';
245 is $x, 1, 'given/default/given/when - reap at default [ok 2 - x]';
246 is $y, 1, 'given/default/given/when - reap at default [ok 2 - y]';
259 reap { ++$y; die "reaped\n" } => HERE;
260 is $x, 3, 'die in reap at eval [not yet - x]';
261 is $y, undef, 'die in reap at eval [not yet - y]';
262 }; # should trigger here, but the die isn't catched by this eval
265 is $@, "reaped\n", 'die in reap at eval [ok - $@]';
266 is $x, 1, 'die in reap at eval [ok - x]';
267 is $y, 1, 'die in reap at eval [ok - y]';
277 reap { ++$y; die "reaped\n" } => HERE;
278 is $x, 3, 'die in reap inside eval [not yet - x]';
279 is $y, undef, 'die in reap inside eval [not yet - y]';
280 } # should trigger here
283 is $@, "reaped\n", 'die in reap inside eval [ok - $@]';
284 is $x, 1, 'die in reap inside eval [ok - x]';
285 is $y, 1, 'die in reap inside eval [ok - y]';
289 my ($cb, $desc) = @_;
294 is $x, 3, "$desc [not yet 1 - x]";
295 is $y, undef, "$desc [not yet 1 - y]";
297 is $x, 2, "$desc [not yet 2 - x]";
298 is $y, undef, "$desc [not yet 2 - y]";
302 for ([ sub { ++$y; 15, 16, 17, 18 }, 'implicit ' ],
303 [ sub { ++$y; return 15, 16, 17, 18 }, '' ]) {
304 my ($cb, $imp) = @$_;
305 $imp = "RT #44204 - ${imp}return from reap";
309 $desc = "$imp in list context";
311 my @l = hijacked($cb, $desc);
312 is $x, 1, "$desc [ok - x]";
313 is $y, 1, "$desc [ok - y]";
314 is_deeply \@l, [ 11, 12 ], "$desc [ok - l]";
318 $desc = "$imp in list context";
320 my $s = hijacked($cb, $desc);
321 is $x, 1, "$desc [ok - x]";
322 is $y, 1, "$desc [ok - y]";
323 is $s, 12, "$desc [ok - s]";