perl 5.0 alpha 6
[p5sagit/p5-mst-13.2.git] / t / op / goto.t
CommitLineData
8d063cd8 1#!./perl
2
79072805 3# $RCSfile: goto.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:56 $
8d063cd8 4
8990e307 5# "This IS structured code. It's just randomly structured."
6
7print "1..9\n";
8d063cd8 8
79072805 9while ($?) {
8d063cd8 10 $foo = 1;
11 label1:
12 $foo = 2;
13 goto label2;
14} continue {
15 $foo = 0;
16 goto label4;
17 label3:
18 $foo = 4;
19 goto label4;
20}
21goto label1;
22
23$foo = 3;
24
25label2:
26print "#1\t:$foo: == 2\n";
27if ($foo == 2) {print "ok 1\n";} else {print "not ok 1\n";}
28goto label3;
29
30label4:
31print "#2\t:$foo: == 4\n";
32if ($foo == 4) {print "ok 2\n";} else {print "not ok 2\n";}
33
34$x = `./perl -e 'goto foo;' 2>&1`;
8d063cd8 35if ($x =~ /label/) {print "ok 3\n";} else {print "not ok 3\n";}
79072805 36
37sub foo {
38 goto bar;
39 print "not ok 4\n";
40 return;
41bar:
42 print "ok 4\n";
43}
44
45&foo;
46
47sub bar {
8990e307 48 $x = 'bypass';
49 eval "goto $x";
79072805 50}
51
52&bar;
53exit;
8990e307 54
55FINALE:
56print "ok 9\n";
57exit;
58
59bypass:
79072805 60print "ok 5\n";
8990e307 61
62# Test autoloading mechanism.
63
64sub two {
65 ($pack, $file, $line) = caller; # Should indicate original call stats.
66 print "@_ $pack $file $line" eq "1 2 3 main $FILE $LINE"
67 ? "ok 7\n"
68 : "not ok 7\n";
69}
70
71sub one {
72 eval <<'END';
73 sub one { print "ok 6\n"; goto &two; print "not ok 6\n"; }
74END
75 goto &one;
76}
77
78$FILE = __FILE__;
79$LINE = __LINE__ + 1;
80&one(1,2,3);
81
82$wherever = NOWHERE;
83eval { goto $wherever };
84print $@ =~ /Can't find label NOWHERE/ ? "ok 8\n" : "not ok 8\n";
85
86$wherever = FINALE;
87goto $wherever;