3 # "This IS structured code. It's just randomly structured."
24 print "#1\t:$foo: == 2\n";
25 if ($foo == 2) {print "ok 1\n";} else {print "not ok 1\n";}
29 print "#2\t:$foo: == 4\n";
30 if ($foo == 4) {print "ok 2\n";} else {print "not ok 2\n";}
32 $PERL = ($^O eq 'MSWin32') ? '.\perl' : ($^O eq 'MacOS') ? $^X : ($^O eq 'NetWare') ? 'perl' : './perl';
33 $CMD = qq[$PERL -e "goto foo;" 2>&1 ];
36 if ($x =~ /label/) {print "ok 3\n";} else {print "not ok 3\n";}
59 # does goto LABEL handle block contexts correctly?
80 # Does goto work correctly within a for(;;) loop?
81 # (BUG ID 20010309.004)
86 label: print (defined $x?"ok ": "not ok ", "17\n")
89 # Does goto work correctly going *to* a for(;;) loop?
90 # (make sure it doesn't skip the initializer)
93 FORL1: for($y="ok 18\n"; $z;) {print $y; goto TEST19}
94 ($y,$z) = ("not ok 18\n", 1);
97 # Even from within the loop?
100 FORL2: for($y="ok 19\n"; 1;) {
105 ($y, $z) = ("not ok 19\n", 1);
109 # Does goto work correctly within a try block?
110 # (BUG ID 20000313.004)
116 LABEL20: $ok = 1 if $variable;
118 print ($ok&&!$@ ? "ok 20\n" : "not ok 20\n");
120 # And within an eval-string?
127 LABEL21: $ok = 1 if $variable;
129 print ($ok&&!$@ ? "ok 21\n" : "not ok 21\n");
132 # Test that goto works in nested eval-string
145 print ($ok ? "ok 22\n" : "not ok 22\n");
151 { goto A; A: $ok = 1 } continue { }
152 print "not " unless $ok;
153 print "ok 23 - #20357 goto inside /{ } continue { }/ loop\n";
156 { do { goto A; A: $ok = 1 } while $false }
157 print "not " unless $ok;
158 print "ok 24 - #20154 goto inside /do { } while ()/ loop\n";
161 foreach(1) { goto A; A: $ok = 1 } continue { };
162 print "not " unless $ok;
163 print "ok 25 - goto inside /foreach () { } continue { }/ loop\n";
167 A: { if ($false) { redo A; B: $ok = 1; redo A; } }
171 print "not " unless $ok;
172 print "ok 26 - #19061 loop label wiped away by goto\n";
175 for ($p=1;$p && goto A;$p=0) { A: $ok = 1 }
176 print "not " unless $ok;
177 print "ok 27 - weird case of goto and for(;;) loop\n";
180 # bug #9990 - don't prematurely free the CV we're &going to.
184 goto sub { $x; print "ok 28 - don't prematurely free CV\n" }
193 # Test autoloading mechanism.
196 ($pack, $file, $line) = caller; # Should indicate original call stats.
197 print "@_ $pack $file $line" eq "1 2 3 main $FILE $LINE"
204 sub one { print "ok 6\n"; goto &two; print "not ok 6\n"; }
210 $LINE = __LINE__ + 1;
214 eval { goto $wherever };
215 print $@ =~ /Can't find label NOWHERE/ ? "ok 8\n" : "not ok 8\n";
217 # see if a modified @_ propagates
220 sub DESTROY { my $s = shift; print "ok $s->[0]\n"; }
221 sub show { print "# @_\nnot ok $_[0][0]\n" if @_ != 5; }
222 sub start { push @_, 1, "foo", {}; goto &show; }
223 for (9..11) { start(bless([$_]), 'bar'); }
230 sub AUTOLOAD { print @_ }