Skip to content

Commit f5c18c3

Browse files
committed
Add tests for exceptions to now-fatalized uses of goto LABEL
We extract the 'got' portion from these tests as they previously appeared in this file; eval that string, which generates an exception. We then confirm it's the exception message we were expecting. For the test description we re-use the previous description.
1 parent f31afb2 commit f5c18c3

File tree

1 file changed

+152
-1
lines changed

1 file changed

+152
-1
lines changed

t/op/goto.t

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ BEGIN {
1212
use warnings;
1313
use strict;
1414
use Config;
15-
plan tests => 52;
15+
plan tests => 75;
1616

1717
our $TODO;
1818

@@ -556,3 +556,154 @@ pass("bug 132799");
556556
"goto LABEL can't be used to go into a construct that is optimized away");
557557
}
558558

559+
note("Tests of functionality fatalized in Perl 5.44");
560+
my $msg = q|Use of "goto" to jump into a construct is no longer permitted|;
561+
562+
{
563+
564+
local $@;
565+
my $false = 0;
566+
my $thisok = 0;
567+
568+
eval {
569+
for (my $p=1; $p && goto A; $p=0) {
570+
A: $thisok = 1;
571+
}
572+
};
573+
like($@, qr/$msg/,
574+
'Got expected exception; formerly: following goto and for(;;) loop');
575+
576+
eval {
577+
\sub :lvalue { goto d; ${*{scalar(do { d: \*foo })}} }->();
578+
};
579+
like($@, qr/$msg/,
580+
'Got expected exception; formerly: goto into rv2sv, rv2gv and scalar');
581+
582+
eval {
583+
sub { goto e; $#{; do { e: \@_ } } }->(1..7);
584+
};
585+
like($@, qr/$msg/,
586+
'Got expected exception; formerly: goto into $#{...}');
587+
588+
eval {
589+
sub { goto f; prototype \&{; do { f: sub ($) {} } } }->();
590+
};
591+
like($@, qr/$msg/,
592+
'Got expected exception; formerly: goto into srefgen, prototype and rv2cv');
593+
594+
eval {
595+
sub { goto g; ref do { g: [] } }->();
596+
};
597+
like($@, qr/$msg/,
598+
'Got expected exception; formerly: goto into ref');
599+
600+
eval {
601+
sub { goto j; defined undef ${; do { j: \(my $foo = "foo") } } }->();
602+
};
603+
like($@, qr/$msg/,
604+
'Got expected exception; formerly: goto into defined and undef');
605+
606+
eval {
607+
sub { goto k; study ++${; do { k: \(my $foo = "foo") } } }->();
608+
};
609+
like($@, qr/$msg/,
610+
'Got expected exception; formerly: goto into study and preincrement');
611+
612+
eval {
613+
sub { goto l; ~-!${; do { l: \(my $foo = 0) } }++ }->();
614+
};
615+
like($@, qr/$msg/,
616+
'Got expected exception; formerly: goto into complement, not, negation and postincrement');
617+
618+
eval {
619+
sub { goto n; sin cos exp log sqrt do { n: 1 } }->();
620+
};
621+
like($@, qr/$msg/,
622+
'Got expected exception; formerly: goto into sin, cos, exp, log, and sqrt');
623+
624+
eval {
625+
sub { goto o; srand do { o: 0 } }->();
626+
};
627+
like($@, qr/$msg/,
628+
'Got expected exception; formerly: goto into srand');
629+
630+
eval {
631+
sub { goto p; rand do { p: 1 } }->();
632+
};
633+
like($@, qr/$msg/,
634+
'Got expected exception; formerly: goto into rand');
635+
636+
eval {
637+
sub { goto r; chr ord length int hex oct abs do { r: -15.5 } }->();
638+
};
639+
like($@, qr/$msg/,
640+
'Got expected exception; formerly: goto into chr, ord, length, int, hex, oct and abs');
641+
642+
eval {
643+
sub { goto t; ucfirst lcfirst uc lc do { t: "q" } }->();
644+
};
645+
like($@, qr/$msg/,
646+
'Got expected exception; formerly: goto into ucfirst, lcfirst, uc and lc');
647+
648+
eval {
649+
sub { goto u; \@{; quotemeta do { u: "." } } }->();
650+
};
651+
like($@, qr/$msg/,
652+
'Got expected exception; formerly: goto into rv2av and quotemeta');
653+
654+
eval {
655+
join(" ",sub { goto v; %{; do { v: +{1..2} } } }->());
656+
};
657+
like($@, qr/$msg/,
658+
'Got expected exception; formerly: goto into rv2hv');
659+
660+
eval {
661+
join(" ",sub { goto w; $_ || do { w: "w" } }->());
662+
};
663+
like($@, qr/$msg/,
664+
'Got expected exception; formerly: goto into rhs of or');
665+
666+
eval {
667+
join(" ",sub { goto x; $_ && do { x: "w" } }->());
668+
};
669+
like($@, qr/$msg/,
670+
'Got expected exception; formerly: goto into rhs of and');
671+
672+
eval {
673+
join(" ",sub { goto z; $_ ? do { z: "w" } : 0 }->());
674+
};
675+
like($@, qr/$msg/,
676+
'Got expected exception; formerly: goto into first leg of ?:');
677+
678+
eval {
679+
join(" ",sub { goto z; $_ ? 0 : do { z: "w" } }->());
680+
};
681+
like($@, qr/$msg/,
682+
'Got expected exception; formerly: goto into second leg of ?:');
683+
684+
eval {
685+
sub { goto z; caller do { z: 0 } }->();
686+
};
687+
like($@, qr/$msg/,
688+
'Got expected exception; formerly: goto into caller');
689+
690+
eval {
691+
sub { goto z; exit do { z: return "foo" } }->();
692+
};
693+
like($@, qr/$msg/,
694+
'Got expected exception; formerly: goto into exit');
695+
696+
eval {
697+
sub { goto z; eval do { z: "'foo'" } }->();
698+
};
699+
like($@, qr/$msg/,
700+
'Got expected exception; formerly: goto into eval');
701+
702+
eval {
703+
join(",",sub { goto z; glob do { z: "foo bar" } }->());
704+
};
705+
like($@, qr/$msg/,
706+
'Got expected exception; formerly: goto into glob');
707+
708+
}
709+

0 commit comments

Comments
 (0)