goto.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
# "This IS structured code. It's just randomly structured."
print "1..16\n";
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";
$x = `$CMD`;
sub foo {
goto bar;
print "not ok 4\n";
return;
bar:
print "ok 4\n";
}
&foo;
sub bar {
$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";
exit;
print "ok 5\n";
# Test autoloading mechanism.
sub two {
? "ok 7\n"
: "not ok 7\n";
}
sub one {
eval <<'END';
goto &one;
}
&one(1,2,3);
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;