6 use Test::More tests => 41 + 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]';
129 reap { $reaped = 1 };
130 is $reaped, 0, 'died of natural death - not reaped yet';
134 is $reaped, 1, 'died of natural death - reaped';
135 like $err, qr/division by zero/, 'died of natural death - divided by zero';
140 skip 'Perl 5.10 required to test given/when' => 30 if "$]" < 5.010;
141 skip 'Not testing deprecated given/when on Perl 5.37.10 or later'
142 => 30 if "$]" >= 5.037010;
144 eval <<' GIVEN_TEST_1';
146 if ("$]" >= 5.017_011) {
148 warnings->unimport('experimental::smartmatch');
151 use feature 'switch';
160 is $x, 3, 'given/when - reap at given [not yet - x]';
161 is $y, undef, 'given/when - reap at given [not yet - y]';
165 is $x, 1, 'given/when - reap at given [ok - x]';
166 is $y, 1, 'given/when - reap at given [ok - y]';
171 eval <<' GIVEN_TEST_2';
173 if ("$]" >= 5.017_011) {
175 warnings->unimport('experimental::smartmatch');
178 use feature 'switch';
187 is $x, 3, 'given/when/continue - reap at given [not yet 1 - x]';
188 is $y, undef, 'given/when/continue - reap at given [not yet 1 - y]';
191 is $x, 2, 'given/when/continue - reap at given [not yet 2 - x]';
192 is $y, undef, 'given/when/continue - reap at given [not yet 2 - y]';
194 is $x, 1, 'given/when/continue - reap at given [ok - x]';
195 is $y, 1, 'given/when/continue - reap at given [ok - y]';
200 eval <<' GIVEN_TEST_3';
202 if ("$]" >= 5.017_011) {
204 warnings->unimport('experimental::smartmatch');
207 use feature 'switch';
216 is $x, 3, 'given/default - reap at given [not yet - x]';
217 is $y, undef, 'given/default - reap at given [not yet - y]';
221 is $x, 1, 'given/default - reap at given [ok - x]';
222 is $y, 1, 'given/default - reap at given [ok - y]';
227 eval <<' GIVEN_TEST_4';
229 if ("$]" >= 5.017_011) {
231 warnings->unimport('experimental::smartmatch');
234 use feature 'switch';
243 is $x, 3, 'given/default/continue - reap at given [not yet 1 - x]';
244 is $y, undef, 'given/default/continue - reap at given [not yet 1 - y]';
247 is $x, 2, 'given/default/continue - reap at given [not yet 2 - x]';
248 is $y, undef, 'given/default/continue - reap at given [not yet 2 - y]';
250 is $x, 1, 'given/default/continue - reap at given [ok - x]';
251 is $y, 1, 'given/default/continue - reap at given [ok - y]';
256 eval <<' GIVEN_TEST_5';
258 if ("$]" >= 5.017_011) {
260 warnings->unimport('experimental::smartmatch');
263 use feature 'switch';
275 reap \&check => UP UP;
276 is $x, 5, 'given/default/given/when - reap at default [not yet 1 - x]';
277 is $y, undef, 'given/default/given/when - reap at default [not yet 1 - y]';
280 is $x, 4, 'given/default/given/when - reap at default [not yet 2 - x]';
281 is $y, undef, 'given/default/given/when - reap at default [not yet 2 - y]';
283 is $x, 3, 'given/default/given/when - reap at default [not yet 3 - x]';
284 is $y, undef, 'given/default/given/when - reap at default [not yet 3 - y]';
287 is $x, 2, 'given/default/given/when - reap at default [ok 1 - x]';
288 is $y, 1, 'given/default/given/when - reap at default [ok 1 - y]';
290 is $x, 1, 'given/default/given/when - reap at default [ok 2 - x]';
291 is $y, 1, 'given/default/given/when - reap at default [ok 2 - y]';
304 reap { ++$y; die "reaped\n" } => HERE;
305 is $x, 3, 'die in reap at eval [not yet - x]';
306 is $y, undef, 'die in reap at eval [not yet - y]';
307 }; # should trigger here, but the die isn't catched by this eval in
311 is $@, ($] >= 5.023008 ? "inner\n" : "reaped\n"),
312 'die in reap at eval [ok - $@]';
313 is $x, 1, 'die in reap at eval [ok - x]';
314 is $y, 1, 'die in reap at eval [ok - y]';
324 reap { ++$y; die "reaped\n" } => HERE;
325 is $x, 3, 'die in reap inside eval [not yet - x]';
326 is $y, undef, 'die in reap inside eval [not yet - y]';
327 } # should trigger here
330 is $@, "reaped\n", 'die in reap inside eval [ok - $@]';
331 is $x, 1, 'die in reap inside eval [ok - x]';
332 is $y, 1, 'die in reap inside eval [ok - y]';
336 my ($cb, $desc) = @_;
341 is $x, 3, "$desc [not yet 1 - x]";
342 is $y, undef, "$desc [not yet 1 - y]";
344 is $x, 2, "$desc [not yet 2 - x]";
345 is $y, undef, "$desc [not yet 2 - y]";
349 for ([ sub { ++$y; 15, 16, 17, 18 }, 'implicit ' ],
350 [ sub { ++$y; return 15, 16, 17, 18 }, '' ]) {
351 my ($cb, $imp) = @$_;
352 $imp = "RT #44204 - ${imp}return from reap";
356 $desc = "$imp in list context";
358 my @l = hijacked($cb, $desc);
359 is $x, 1, "$desc [ok - x]";
360 is $y, 1, "$desc [ok - y]";
361 is_deeply \@l, [ 11, 12 ], "$desc [ok - l]";
365 $desc = "$imp in list context";
367 my $s = hijacked($cb, $desc);
368 is $x, 1, "$desc [ok - x]";
369 is $y, 1, "$desc [ok - y]";
370 is $s, 12, "$desc [ok - s]";