Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
8990e307 LW |
3 | # "This IS structured code. It's just randomly structured." |
4 | ||
62b1ebc2 | 5 | print "1..12\n"; |
8d063cd8 | 6 | |
79072805 | 7 | while ($?) { |
8d063cd8 LW |
8 | $foo = 1; |
9 | label1: | |
10 | $foo = 2; | |
11 | goto label2; | |
12 | } continue { | |
13 | $foo = 0; | |
14 | goto label4; | |
15 | label3: | |
16 | $foo = 4; | |
17 | goto label4; | |
18 | } | |
19 | goto label1; | |
20 | ||
21 | $foo = 3; | |
22 | ||
23 | label2: | |
24 | print "#1\t:$foo: == 2\n"; | |
25 | if ($foo == 2) {print "ok 1\n";} else {print "not ok 1\n";} | |
26 | goto label3; | |
27 | ||
28 | label4: | |
29 | print "#2\t:$foo: == 4\n"; | |
30 | if ($foo == 4) {print "ok 2\n";} else {print "not ok 2\n";} | |
31 | ||
68dc0745 | 32 | $PERL = ($^O eq 'MSWin32') ? '.\perl' : './perl'; |
33 | $x = `$PERL -e "goto foo;" 2>&1`; | |
a0d0e21e LW |
34 | if ($x =~ /DCL-W-NOCOMD/) { $x = `\$ mcr sys\$disk:[]perl. -e "goto foo;"`; } |
35 | ||
8d063cd8 | 36 | if ($x =~ /label/) {print "ok 3\n";} else {print "not ok 3\n";} |
79072805 LW |
37 | |
38 | sub foo { | |
39 | goto bar; | |
40 | print "not ok 4\n"; | |
41 | return; | |
42 | bar: | |
43 | print "ok 4\n"; | |
44 | } | |
45 | ||
46 | &foo; | |
47 | ||
48 | sub bar { | |
8990e307 LW |
49 | $x = 'bypass'; |
50 | eval "goto $x"; | |
79072805 LW |
51 | } |
52 | ||
53 | &bar; | |
54 | exit; | |
8990e307 LW |
55 | |
56 | FINALE: | |
62b1ebc2 | 57 | print "ok 12\n"; |
8990e307 LW |
58 | exit; |
59 | ||
60 | bypass: | |
79072805 | 61 | print "ok 5\n"; |
8990e307 LW |
62 | |
63 | # Test autoloading mechanism. | |
64 | ||
65 | sub two { | |
66 | ($pack, $file, $line) = caller; # Should indicate original call stats. | |
67 | print "@_ $pack $file $line" eq "1 2 3 main $FILE $LINE" | |
68 | ? "ok 7\n" | |
69 | : "not ok 7\n"; | |
70 | } | |
71 | ||
72 | sub one { | |
73 | eval <<'END'; | |
74 | sub one { print "ok 6\n"; goto &two; print "not ok 6\n"; } | |
75 | END | |
76 | goto &one; | |
77 | } | |
78 | ||
79 | $FILE = __FILE__; | |
80 | $LINE = __LINE__ + 1; | |
81 | &one(1,2,3); | |
82 | ||
83 | $wherever = NOWHERE; | |
84 | eval { goto $wherever }; | |
85 | print $@ =~ /Can't find label NOWHERE/ ? "ok 8\n" : "not ok 8\n"; | |
86 | ||
62b1ebc2 GS |
87 | # see if a modified @_ propagates |
88 | { | |
89 | package Foo; | |
90 | sub DESTROY { my $s = shift; print "ok $s->[0]\n"; } | |
91 | sub show { print "# @_\nnot ok $_[0][0]\n" if @_ != 5; } | |
92 | sub start { push @_, 1, "foo", {}; goto &show; } | |
93 | for (9..11) { start(bless([$_]), 'bar'); } | |
94 | } | |
95 | ||
8990e307 LW |
96 | $wherever = FINALE; |
97 | goto $wherever; |