goto.t revision 1
1N/A# "This IS structured code. It's just randomly structured." 1N/A chdir 't' if -d 't'; 1N/Aif ($foo == 2) {
print "ok 1\n";}
else {
print "not ok 1\n";}
1N/Aif ($foo == 4) {
print "ok 2\n";}
else {
print "not ok 2\n";}
1N/A$PERL =
($^O eq 'MSWin32') ?
'.\perl' :
($^O eq 'MacOS') ? $^X :
($^O eq 'NetWare') ?
'perl' :
'./perl';
1N/Aif ($x =~ /label/) {
print "ok 3\n";}
else {
print "not ok 3\n";}
1N/A# does goto LABEL handle block contexts correctly? 1N/A# Does goto work correctly within a for(;;) loop? 1N/A# (BUG ID 20010309.004) 1N/Afor(my $i=0;!$i++;) { 1N/A# Does goto work correctly going *to* a for(;;) loop? 1N/A# (make sure it doesn't skip the initializer) 1N/A($y,$z) =
("not ok 18\n", 1);
1N/A# Even from within the loop? 1N/A ($y, $z) = ("not ok 19\n", 1); 1N/A# Does goto work correctly within a try block? 1N/A# (BUG ID 20000313.004) 1N/Aprint ($ok&&!$@ ? "ok 20\n" : "not ok 20\n");
1N/A# And within an eval-string? 1N/Aprint ($ok&&!$@ ? "ok 21\n" : "not ok 21\n");
1N/A# Test that goto works in nested eval-string 1N/Aprint ($ok ? "ok 22\n" : "not ok 22\n");
1N/A { goto A; A: $ok = 1 } continue { } 1N/A print "ok 23 - #20357 goto inside /{ } continue { }/ loop\n"; 1N/A print "ok 24 - #20154 goto inside /do { } while ()/ loop\n"; 1N/A foreach(1) { goto A; A: $ok = 1 } continue { }; 1N/A print "ok 25 - goto inside /foreach () { } continue { }/ loop\n"; 1N/A print "ok 26 - #19061 loop label wiped away by goto\n"; 1N/A for ($p=1;$p && goto A;$p=0) { A: $ok = 1 } 1N/A print "ok 27 - weird case of goto and for(;;) loop\n"; 1N/A# bug #9990 - don't prematurely free the CV we're &going to. 1N/A goto sub { $x; print "ok 28 - don't prematurely free CV\n" } 1N/A# bug #22181 - this used to coredump or make $x undefined, due to 1N/A# erroneous popping of the inner BLOCK context 1N/Afor ($i=0; $i<2; $i++) { 1N/Aprint "ok 29 - goto in for(;;) with continuation\n"; 1N/A# bug #22299 - goto in require doesn't find label 1N/Ais($r, "OK\nDONE\n", "goto within use-d file"); 1N/A# test for [perl #24108] 1N/A print "ok 31 - i_return_a_label called\n"; 1N/A return "returned_label"; 1N/A# Test autoloading mechanism. 1N/A sub one { print "ok 6\n"; goto &two; print "not ok 6\n"; } 1N/Aprint $@ =~ /Can't find label NOWHERE/ ? "ok 8\n" : "not ok 8\n"; 1N/A# see if a modified @_ propagates 1N/A sub DESTROY { my $s = shift; print "ok $s->[0]\n"; } 1N/A sub show { print "# @_\nnot ok $_[0][0]\n" if @_ != 5; } 1N/A sub start { push @_, 1, "foo", {}; goto &show; } 1N/A for (9..11) { start(bless([$_]), 'bar'); } 1N/Asub AUTOLOAD { print @_ }