3 # "This IS structured code. It's just randomly structured."
31 print "#1\t:$foo: == 2\n";
32 if ($foo == 2) {print "ok 1\n";} else {print "not ok 1\n";}
36 print "#2\t:$foo: == 4\n";
37 if ($foo == 4) {print "ok 2\n";} else {print "not ok 2\n";}
39 $PERL = ($^O eq 'MSWin32') ? '.\perl' : ($^O eq 'MacOS') ? $^X : ($^O eq 'NetWare') ? 'perl' : './perl';
40 $CMD = qq[$PERL -e "goto foo;" 2>&1 ];
43 if ($x =~ /label/) {print "ok 3\n";} else {print "not ok 3\n";}
66 # does goto LABEL handle block contexts correctly?
87 # Does goto work correctly within a for(;;) loop?
88 # (BUG ID 20010309.004)
93 label: print (defined $x?"ok ": "not ok ", "17\n")
96 # Does goto work correctly going *to* a for(;;) loop?
97 # (make sure it doesn't skip the initializer)
100 FORL1: for($y="ok 18\n"; $z;) {print $y; goto TEST19}
101 ($y,$z) = ("not ok 18\n", 1);
104 # Even from within the loop?
107 FORL2: for($y="ok 19\n"; 1;) {
112 ($y, $z) = ("not ok 19\n", 1);
116 # Does goto work correctly within a try block?
117 # (BUG ID 20000313.004)
123 LABEL20: $ok = 1 if $variable;
125 print ($ok&&!$@ ? "ok 20\n" : "not ok 20\n");
127 # And within an eval-string?
134 LABEL21: $ok = 1 if $variable;
136 print ($ok&&!$@ ? "ok 21\n" : "not ok 21\n");
139 # Test that goto works in nested eval-string
152 print ($ok ? "ok 22\n" : "not ok 22\n");
158 { goto A; A: $ok = 1 } continue { }
159 print "not " unless $ok;
160 print "ok 23 - #20357 goto inside /{ } continue { }/ loop\n";
163 { do { goto A; A: $ok = 1 } while $false }
164 print "not " unless $ok;
165 print "ok 24 - #20154 goto inside /do { } while ()/ loop\n";
168 foreach(1) { goto A; A: $ok = 1 } continue { };
169 print "not " unless $ok;
170 print "ok 25 - goto inside /foreach () { } continue { }/ loop\n";
174 A: { if ($false) { redo A; B: $ok = 1; redo A; } }
178 print "not " unless $ok;
179 print "ok 26 - #19061 loop label wiped away by goto\n";
182 for ($p=1;$p && goto A;$p=0) { A: $ok = 1 }
183 print "not " unless $ok;
184 print "ok 27 - weird case of goto and for(;;) loop\n";
187 # bug #9990 - don't prematurely free the CV we're &going to.
191 goto sub { $x; print "ok 28 - don't prematurely free CV\n" }
195 # bug #22181 - this used to coredump or make $x undefined, due to
196 # erroneous popping of the inner BLOCK context
198 for ($i=0; $i<2; $i++) {
202 print "not " if !defined $x || $x != 1;
204 print "ok 29 - goto in for(;;) with continuation\n";
206 # bug #22299 - goto in require doesn't find label
208 open my $f, ">goto01.pm" or die;
219 my $r = runperl(prog => 'use goto01; print qq[DONE\n]');
220 is($r, "OK\nDONE\n", "goto within use-d file");
229 # Test autoloading mechanism.
232 ($pack, $file, $line) = caller; # Should indicate original call stats.
233 print "@_ $pack $file $line" eq "1 2 3 main $FILE $LINE"
240 sub one { print "ok 6\n"; goto &two; print "not ok 6\n"; }
246 $LINE = __LINE__ + 1;
250 eval { goto $wherever };
251 print $@ =~ /Can't find label NOWHERE/ ? "ok 8\n" : "not ok 8\n";
253 # see if a modified @_ propagates
256 sub DESTROY { my $s = shift; print "ok $s->[0]\n"; }
257 sub show { print "# @_\nnot ok $_[0][0]\n" if @_ != 5; }
258 sub start { push @_, 1, "foo", {}; goto &show; }
259 for (9..11) { start(bless([$_]), 'bar'); }
266 sub AUTOLOAD { print @_ }