@@ -12,49 +12,31 @@ BEGIN {
1212use warnings;
1313use strict;
1414use Config;
15- skip_all(" Being overhauled in GH #23618" );
16- # plan tests => 95;
15+ plan tests => 47;
1716
1817our $TODO ;
1918
20- my $deprecated = 0;
21-
22- local $SIG {__WARN__ } = sub {
23- if ($_ [0] =~ m / jump into a construct.*?, and will become fatal in Perl 5\. 42/ ) {
24- $deprecated ++;
25- }
26- else { warn $_ [0] }
27- };
28-
2919our $foo ;
3020while ($? ) {
3121 $foo = 1;
3222 label1:
33- is($deprecated , 1, " following label1" );
34- $deprecated = 0;
3523 $foo = 2;
3624 goto label2;
3725} continue {
3826 $foo = 0;
3927 goto label4;
4028 label3:
41- is($deprecated , 1, " following label3" );
42- $deprecated = 0;
4329 $foo = 4;
4430 goto label4;
4531}
46- is($deprecated , 0, " after 'while' loop" );
47- goto label1;
4832
4933$foo = 3;
5034
5135label2:
52- is($foo , 2, ' escape while loop' );
53- is($deprecated , 0, " following label2" );
54- goto label3;
36+ is($foo , 3, ' escape while loop' );
5537
5638label4:
57- is($foo , 4 , ' second escape while loop' );
39+ is($foo , 3 , ' second escape while loop' );
5840
5941my $r = run_perl(prog => ' goto foo;' , stderr => 1);
6042like($r , qr / label/ , ' cant find label' );
@@ -76,11 +58,7 @@ sub bar {
7658}
7759
7860&bar;
79- fail(' goto bypass' );
80- exit ;
81-
82- FINALE:
83- is(curr_test(), 11, ' FINALE' );
61+ pass(' goto bypass' );
8462
8563# does goto LABEL handle block contexts correctly?
8664# note that this scope-hopping differs from last & next,
@@ -192,20 +170,10 @@ ok($ok, 'works correctly in a nested eval string');
192170 $ok = 0;
193171 sub a {
194172 A: { if ($false ) { redo A; B: $ok = 1; redo A; } }
195- goto B unless $count ++;
196173 }
197- is($deprecated , 0, " before calling sub a()" );
198174 a();
199- ok($ok , ' #19061 loop label wiped away by goto' );
200- is($deprecated , 1, " after calling sub a()" );
201- $deprecated = 0;
202175
203176 $ok = 0;
204- my $p ;
205- for ($p =1;$p && goto A;$p =0) { A: $ok = 1 }
206- ok($ok , ' weird case of goto and for(;;) loop' );
207- is($deprecated , 1, " following goto and for(;;) loop" );
208- $deprecated = 0;
209177}
210178
211179# bug #22181 - this used to coredump or make $x undefined, due to
@@ -250,110 +218,6 @@ returned_label:
250218is($count , 1, ' called i_return_a_label' );
251219ok($ok , ' skipped to returned_label' );
252220
253- goto moretests;
254- fail(' goto moretests' );
255- exit ;
256-
257- bypass:
258-
259- is(curr_test(), 9, ' eval "goto $x"' );
260-
261- {
262- my $wherever = ' NOWHERE' ;
263- eval { goto $wherever };
264- like($@ , qr / Can't find label NOWHERE/ , ' goto NOWHERE sets $@' );
265- }
266-
267- {
268- my $wherever = ' FINALE' ;
269- goto $wherever ;
270- }
271- fail(' goto $wherever' );
272-
273- moretests:
274- # test goto duplicated labels.
275- {
276- my $z = 0;
277- eval {
278- $z = 0;
279- for (0..1) {
280- L4: # not outer scope
281- $z += 10;
282- last ;
283- }
284- goto L4 if $z == 10;
285- last ;
286- };
287- like($@ , qr / Can't "goto" into the middle of a foreach loop/ ,
288- ' catch goto middle of foreach' );
289-
290- $z = 0;
291- # ambiguous label resolution (outer scope means endless loop!)
292- L1:
293- for my $x (0..1) {
294- $z += 10;
295- is($z , 10, ' prefer same scope (loop body) to outer scope (loop entry)' );
296- goto L1 unless $x ;
297- $z += 10;
298- L1:
299- is($z , 10, ' prefer same scope: second' );
300- last ;
301- }
302-
303- $z = 0;
304- L2:
305- {
306- $z += 10;
307- is($z , 10, ' prefer this scope (block body) to outer scope (block entry)' );
308- goto L2 if $z == 10;
309- $z += 10;
310- L2:
311- is($z , 10, ' prefer this scope: second' );
312- }
313-
314-
315- {
316- $z = 0;
317- while (1) {
318- L3: # not inner scope
319- $z += 10;
320- last ;
321- }
322- is($z , 10, ' prefer this scope to inner scope' );
323- goto L3 if $z == 10;
324- $z += 10;
325- L3: # this scope !
326- is($z , 10, ' prefer this scope to inner scope: second' );
327- }
328-
329- L4: # not outer scope
330- {
331- $z = 0;
332- while (1) {
333- L4: # not inner scope
334- $z += 1;
335- last ;
336- }
337- is($z , 1, ' prefer this scope to inner,outer scopes' );
338- goto L4 if $z == 1;
339- $z += 10;
340- L4: # this scope !
341- is($z , 1, ' prefer this scope to inner,outer scopes: second' );
342- }
343-
344- {
345- my $loop = 0;
346- for my $x (0..1) {
347- L2: # without this, fails 1 (middle) out of 3 iterations
348- $z = 0;
349- L2:
350- $z += 10;
351- is($z , 10,
352- " same label, multiple times in same scope (choose 1st) $loop " );
353- goto L2 if $z == 10 and not $loop ++;
354- }
355- }
356- }
357221
358222# This bug was introduced in Aug 2010 by commit ac56e7de46621c6f
359223# Peephole optimise adjacent pairs of nextstate ops.
@@ -385,8 +249,6 @@ sub DEBUG_TIME() {
385249 };
386250}
387251
388- is($deprecated , 0, ' no warning was emitted' );
389-
390252{
391253 my $r = runperl(
392254 stderr => 1,
@@ -414,8 +276,6 @@ TODO: {
414276 }
415277}
416278
417- is($deprecated , 0, " following TODOed test for #43403" );
418-
419279# 74290
420280{
421281 my $x ;
@@ -610,58 +470,7 @@ sub revnumcmp ($$) {
610470is eval { join (" :" , sort revnumcmp (9,5,1,3,7)) }, " 9:7:5:3:1" ,
611471 " can goto at top level of multicalled sub" ;
612472
613- # A bit strange, but goingto these constructs should not cause any stack
614- # problems. Let’s test them to make sure that is the case.
615- no warnings ' deprecated' ;
616- is \sub :lvalue { goto d; ${*{scalar (do { d: \*foo })}} }-> (), \$foo ,
617- ' goto into rv2sv, rv2gv and scalar' ;
618- is sub { goto e; $# {; do { e: \@_ } } }-> (1..7), 6,
619- ' goto into $#{...}' ;
620- is sub { goto f; prototype \&{; do { f: sub ($) {} } } }-> (), ' $' ,
621- ' goto into srefgen, prototype and rv2cv' ;
622- is sub { goto g; ref do { g: [] } }-> (), ' ARRAY' ,
623- ' goto into ref' ;
624- is sub { goto j; defined undef ${; do { j: \(my $foo = " foo" ) } } }-> (),' ' ,
625- ' goto into defined and undef' ;
626- is sub { goto k; study ++${; do { k: \(my $foo = " foo" ) } } }-> (),' 1' ,
627- ' goto into study and preincrement' ;
628- is sub { goto l; ~-!${; do { l: \(my $foo = 0) } }++ }-> (),~-1,
629- ' goto into complement, not, negation and postincrement' ;
630- like sub { goto n; sin cos exp log sqrt do { n: 1 } }-> (),qr / ^0\. 51439/ ,
631- ' goto into sin, cos, exp, log, and sqrt' ;
632- ok sub { goto o; srand do { o: 0 } }-> (),
633- ' goto into srand' ;
634- cmp_ok sub { goto p; rand do { p: 1 } }-> (), ' <' , 1,
635- ' goto into rand' ;
636- is sub { goto r; chr ord length int hex oct abs do { r: -15.5 } }-> (), 2,
637- ' goto into chr, ord, length, int, hex, oct and abs' ;
638- is sub { goto t; ucfirst lcfirst uc lc do { t: " q" } }-> (), ' Q' ,
639- ' goto into ucfirst, lcfirst, uc and lc' ;
640- { no strict;
641- is sub { goto u; \@{; quotemeta do { u: " ." } } }-> (), \@{' \.' },
642- ' goto into rv2av and quotemeta' ;
643- }
644- is join (" " ,sub { goto v; %{; do { v: +{1..2} } } }-> ()), ' 1 2' ,
645- ' goto into rv2hv' ;
646- is join (" " ,sub { goto w; $_ || do { w: " w" } }-> ()), ' w' ,
647- ' goto into rhs of or' ;
648- is join (" " ,sub { goto x; $_ && do { x: " w" } }-> ()), ' w' ,
649- ' goto into rhs of and' ;
650- is join (" " ,sub { goto z; $_ ? do { z: " w" } : 0 }-> ()), ' w' ,
651- ' goto into first leg of ?:' ;
652- is join (" " ,sub { goto z; $_ ? 0 : do { z: " w" } }-> ()), ' w' ,
653- ' goto into second leg of ?:' ;
654- is sub { goto z; caller do { z: 0 } }-> (), ' main' ,
655- ' goto into caller' ;
656- is sub { goto z; exit do { z: return " foo" } }-> (), ' foo' ,
657- ' goto into exit' ;
658- is sub { goto z; eval do { z: " 'foo'" } }-> (), ' foo' ,
659- ' goto into eval' ;
660- TODO: {
661- local $TODO = " glob() does not currently return a list on VMS" if $^O eq ' VMS' ;
662- is join (" ," ,sub { goto z; glob do { z: " foo bar" } }-> ()), ' foo,bar' ,
663- ' goto into glob' ;
664- }
473+
665474# [perl #132799]
666475# Erroneous inward goto warning, followed by crash.
667476# The eval must be in an assignment.
@@ -674,13 +483,3 @@ sub _routine {
674483_routine();
675484pass(" bug 132799" );
676485
677- # [perl #132854]
678- # Goto the *first* parameter of a binary expression, which is harmless.
679- eval {
680- goto __GEN_2;
681- my $sent = do {
682- __GEN_2:
683- };
684- };
685- is $@ ,' ' , ' goto the first parameter of a binary expression [perl #132854]' ;
686-
0 commit comments