Skip to content

Commit 7dd8ff7

Browse files
committed
Move 10 more tests
1 parent 1f167b4 commit 7dd8ff7

File tree

2 files changed

+72
-69
lines changed

2 files changed

+72
-69
lines changed

t/op/goto-amp-name.t

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use warnings;
1111
use strict;
1212
use Config;
1313
#plan tests => 'no_plan'; # yet
14-
plan tests => 12;
14+
plan tests => 22;
1515
our $TODO;
1616

1717
# Excerpts from 'perldoc -f goto' as of perl-5.40.1 (Aug 2025)
@@ -57,6 +57,75 @@ local $SIG{__WARN__} = sub {
5757

5858
our $foo;
5959

60+
###################
61+
62+
# goto &foo not allowed in evals
63+
64+
sub null { 1 };
65+
eval 'goto &null';
66+
like($@, qr/Can't goto subroutine from an eval-string/, 'eval string');
67+
eval { goto &null };
68+
like($@, qr/Can't goto subroutine from an eval-block/, 'eval block');
69+
70+
# goto &foo leaves @_ alone when called from a sub
71+
sub returnarg { $_[0] };
72+
is sub {
73+
local *_ = ["ick and queasy"];
74+
goto &returnarg;
75+
}->("quick and easy"), "ick and queasy",
76+
'goto &foo with *_{ARRAY} replaced';
77+
my @__ = byte_utf8a_to_utf8n("\xc4\x80");
78+
sub { local *_ = \@__; goto &utf8::decode }->("no thinking aloud");
79+
is "@__", chr 256, 'goto &xsub with replaced *_{ARRAY}';
80+
81+
# And goto &foo should leave reified @_ alone
82+
sub { *__ = \@_; goto &null } -> ("rough and tubbery");
83+
is ${*__}[0], 'rough and tubbery', 'goto &foo leaves reified @_ alone';
84+
85+
# goto &xsub when @_ has nonexistent elements
86+
{
87+
no warnings "uninitialized";
88+
local @_ = ();
89+
$#_++;
90+
& {sub { goto &utf8::encode }};
91+
is @_, 1, 'num of elems in @_ after goto &xsub with nonexistent $_[0]';
92+
is $_[0], "", 'content of nonexistent $_[0] is modified by goto &xsub';
93+
}
94+
95+
# goto &xsub when @_ itself does not exist
96+
undef *_;
97+
eval { & { sub { goto &utf8::encode } } };
98+
# The main thing we are testing is that it did not crash. But make sure
99+
# *_{ARRAY} was untouched, too.
100+
is *_{ARRAY}, undef, 'goto &xsub when @_ does not exist';
101+
102+
# goto &perlsub when @_ itself does not exist [perl #119949]
103+
# This was only crashing when the replaced sub call had an argument list.
104+
# (I.e., &{ sub { goto ... } } did not crash.)
105+
sub {
106+
undef *_;
107+
goto sub {
108+
is *_{ARRAY}, undef, 'goto &perlsub when @_ does not exist';
109+
}
110+
}->();
111+
sub {
112+
local *_;
113+
goto sub {
114+
is *_{ARRAY}, undef, 'goto &sub when @_ does not exist (local *_)';
115+
}
116+
}->();
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
60129
# [perl #36521] goto &foo in warn handler could defeat recursion avoider
61130

62131
{

t/op/goto.t

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use warnings;
1313
use strict;
1414
use Config;
1515
#plan tests => 134;
16-
plan tests => 123;
16+
plan tests => 113;
1717
our $TODO;
1818

1919
my $deprecated = 0;
@@ -540,73 +540,7 @@ a32039();
540540
is($r, "ok\n", 'redo and goto');
541541
}
542542

543-
# goto &foo not allowed in evals
544-
545-
sub null { 1 };
546-
eval 'goto &null';
547-
like($@, qr/Can't goto subroutine from an eval-string/, 'eval string');
548-
eval { goto &null };
549-
like($@, qr/Can't goto subroutine from an eval-block/, 'eval block');
550-
551-
# goto &foo leaves @_ alone when called from a sub
552-
sub returnarg { $_[0] };
553-
is sub {
554-
local *_ = ["ick and queasy"];
555-
goto &returnarg;
556-
}->("quick and easy"), "ick and queasy",
557-
'goto &foo with *_{ARRAY} replaced';
558-
my @__ = byte_utf8a_to_utf8n("\xc4\x80");
559-
sub { local *_ = \@__; goto &utf8::decode }->("no thinking aloud");
560-
is "@__", chr 256, 'goto &xsub with replaced *_{ARRAY}';
561-
562-
# And goto &foo should leave reified @_ alone
563-
sub { *__ = \@_; goto &null } -> ("rough and tubbery");
564-
is ${*__}[0], 'rough and tubbery', 'goto &foo leaves reified @_ alone';
565-
566-
# goto &xsub when @_ has nonexistent elements
567-
{
568-
no warnings "uninitialized";
569-
local @_ = ();
570-
$#_++;
571-
& {sub { goto &utf8::encode }};
572-
is @_, 1, 'num of elems in @_ after goto &xsub with nonexistent $_[0]';
573-
is $_[0], "", 'content of nonexistent $_[0] is modified by goto &xsub';
574-
}
575-
576-
# goto &xsub when @_ itself does not exist
577-
undef *_;
578-
eval { & { sub { goto &utf8::encode } } };
579-
# The main thing we are testing is that it did not crash. But make sure
580-
# *_{ARRAY} was untouched, too.
581-
is *_{ARRAY}, undef, 'goto &xsub when @_ does not exist';
582-
583-
# goto &perlsub when @_ itself does not exist [perl #119949]
584-
# This was only crashing when the replaced sub call had an argument list.
585-
# (I.e., &{ sub { goto ... } } did not crash.)
586-
sub {
587-
undef *_;
588-
goto sub {
589-
is *_{ARRAY}, undef, 'goto &perlsub when @_ does not exist';
590-
}
591-
}->();
592-
sub {
593-
local *_;
594-
goto sub {
595-
is *_{ARRAY}, undef, 'goto &sub when @_ does not exist (local *_)';
596-
}
597-
}->();
598-
599-
600-
## [perl #36521] goto &foo in warn handler could defeat recursion avoider
601-
#
602-
#{
603-
# my $r = runperl(
604-
# stderr => 1,
605-
# prog => 'my $d; my $w = sub { return if $d++; warn q(bar)}; local $SIG{__WARN__} = sub { goto &$w; }; warn q(foo);'
606-
# );
607-
# like($r, qr/bar/, "goto &foo in warn");
608-
#}
609-
#
543+
610544
TODO: {
611545
local $TODO = "[perl #43403] goto() from an if to an else doesn't undo local () changes";
612546
our $global = "unmodified";

0 commit comments

Comments
 (0)