#!./perl
# "This IS structured code. It's just randomly structured."
BEGIN {
chdir 't' if -d 't';
}
print "1..32\n";
require "test.pl";
while ($?) {
$foo = 1;
$foo = 2;
goto label2;
} continue {
$foo = 0;
goto label4;
$foo = 4;
goto label4;
}
goto label1;
$foo = 3;
print "#1\t:$foo: == 2\n";
goto label3;
print "#2\t:$foo: == 4\n";
$PERL = ($^O eq 'MSWin32') ? '.\perl' : ($^O eq 'MacOS') ? $^X : ($^O eq 'NetWare') ? 'perl' : './perl';
$x = `$CMD`;
goto bar;
print "not ok 4\n";
return;
bar:
print "ok 4\n";
}
&foo;
$x = 'bypass';
eval "goto $x";
}
&bar;
exit;
print "ok 13\n";
# does goto LABEL handle block contexts correctly?
my $cond = 1;
for (1) {
$cond = 0;
goto OTHER;
}
$cond = 2;
print "ok 14\n";
goto THIRD;
}
else {
print "ok 15\n";
}
}
print "ok 16\n";
# Does goto work correctly within a for(;;) loop?
# (BUG ID 20010309.004)
for(my $i=0;!$i++;) {
my $x=1;
goto label;
}
# Does goto work correctly going *to* a for(;;) loop?
# (make sure it doesn't skip the initializer)
my ($z, $y) = (0);
($y,$z) = ("not ok 18\n", 1);
goto FORL1;
# Even from within the loop?
if ($z) {
print $y;
last;
}
($y, $z) = ("not ok 19\n", 1);
goto FORL2;
}
# Does goto work correctly within a try block?
# (BUG ID 20000313.004)
my $ok = 0;
eval {
my $variable = 1;
goto LABEL20;
};
# And within an eval-string?
$ok = 0;
eval q{
my $variable = 1;
goto LABEL21;
};
# Test that goto works in nested eval-string
$ok = 0;
{eval q{
eval q{
goto LABEL22;
};
$ok = 0;
last;
};
$ok = 0 if $@;
}
{
my $false = 0;
$ok = 0;
print "ok 23 - #20357 goto inside /{ } continue { }/ loop\n";
$ok = 0;
print "ok 24 - #20154 goto inside /do { } while ()/ loop\n";
$ok = 0;
print "ok 25 - goto inside /foreach () { } continue { }/ loop\n";
$ok = 0;
sub a {
goto B unless $r++
}
a();
print "ok 26 - #19061 loop label wiped away by goto\n";
$ok = 0;
print "ok 27 - weird case of goto and for(;;) loop\n";
}
# bug #9990 - don't prematurely free the CV we're &going to.
sub f1 {
my $x;
goto sub { $x; print "ok 28 - don't prematurely free CV\n" }
}
# bug #22181 - this used to coredump or make $x undefined, due to
# erroneous popping of the inner BLOCK context
for ($i=0; $i<2; $i++) {
my $x = 1;
goto LABEL29;
}
print "ok 29 - goto in for(;;) with continuation\n";
# bug #22299 - goto in require doesn't find label
print $f <<'EOT';
goto YYY;
die;
1;
close $f;
# test for [perl #24108]
sub i_return_a_label {
print "ok 31 - i_return_a_label called\n";
return "returned_label";
}
print "not ";
exit;
print "ok 5\n";
# Test autoloading mechanism.
sub two {
? "ok 7\n"
: "not ok 7\n";
}
sub one {
eval <<'END';
goto &one;
}
eval { goto $wherever };
print $@ =~ /Can't find label NOWHERE/ ? "ok 8\n" : "not ok 8\n";
# see if a modified @_ propagates
{
package Foo;
sub DESTROY { my $s = shift; print "ok $s->[0]\n"; }
sub show { print "# @_\nnot ok $_[0][0]\n" if @_ != 5; }
sub start { push @_, 1, "foo", {}; goto &show; }
}
sub auto {
goto &loadit;
}
sub AUTOLOAD { print @_ }
auto("ok 12\n");
$wherever = FINALE;
goto $wherever;