Fix the options.
[p5sagit/p5-mst-13.2.git] / ext / B / t / bytecode.t
CommitLineData
46983aad 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = qw(../lib);
6 require './test.pl'; # for run_perl()
7}
8use strict;
9
10my $test = 'bytecode.pl';
11END { 1 while unlink $test }
12
13undef $/;
14my @tests = split /\n###+\n/, <DATA>;
15
16print "1..".($#tests+1)."\n";
17
18my $cnt = 1;
19
20for (@tests) {
21 my $got;
22 my ($script, $expect) = split />>>+\n/;
23 $expect =~ s/\n$//;
24 open T, ">$test"; print T $script; close T;
b7bf3a00 25 $got = run_perl(switches => [ "-MO=Bytecode,-H,-o$test" ],
26 stderr => 1,
46983aad 27 progfile => $test);
28 unless ($?) {
29 $got = run_perl(progfile => $test);
30 unless ($?) {
31 if ($got =~ /^$expect$/) {
32 print "ok $cnt\n";
33 next;
34 } else {
35 print <<"EOT"; next;
36not ok $cnt
37--------- SCRIPT
38$script
39--------- GOT
40$got
41--------- EXPECT
42$expect
43----------------
44
45EOT
46 }
47 }
48 }
49 print <<"EOT";
50--------- SCRIPT
51$script
52--------- $?
53$got
54EOT
55} continue {
56 $cnt++;
57}
58
59__DATA__
60
61print 'hi'
62>>>>
63hi
64############################################################
65for (1,2,3) { print if /\d/ }
66>>>>
67123
68############################################################
69$_ = "xyxyx"; %j=(1,2); s/x/$j{print('z')}/ge; print $_
70>>>>
71zzz2y2y2
72############################################################
73$_ = "xyxyx"; %j=(1,2); s/x/$j{print('z')}/g; print $_
74>>>>
75z2y2y2
76############################################################
77split /a/,"bananarama"; print @_
78>>>>
79bnnrm
80############################################################
81{ package P; sub x { print 'ya' } x }
82>>>>
83ya
84############################################################
85@z = split /:/,"b:r:n:f:g"; print @z
86>>>>
87brnfg
88############################################################
89sub AUTOLOAD { print 1 } &{"a"}()
90>>>>
911
92############################################################
93my $l = 3; $x = sub { print $l }; &$x
94>>>>
953
96############################################################
97my $i = 1;
98my $foo = sub {$i = shift if @_};
99&$foo(3);
100############################################################
46983aad 101$_="\xff\xff"; use utf8; utf8::encode $_; print $_
102>>>>
103\xc3\xbf\xc3\xbf
104############################################################
105$x="Cannot use"; print index $x, "Can"
106>>>>
1070
108############################################################
109my $i=6; eval "print \$i\n"
110>>>>
1116
112############################################################
113BEGIN { %h=(1=>2,3=>4) } print $h{3}
114>>>>
1154
116############################################################
117open our $T,"a"
118############################################################
119print <DATA>
120__DATA__
121a
122b
123>>>>
124a
125b
126############################################################
127BEGIN { tie @a, __PACKAGE__; sub TIEARRAY { bless{} } sub FETCH { 1 } }
128print $a[1]
129>>>>
1301
131############################################################
132my $i=3; print 1 .. $i
133>>>>
134123
135############################################################
136my $h = { a=>3, b=>1 }; print sort {$h->{$a} <=> $h->{$b}} keys %$h
137>>>>
138ba
139############################################################
140print sort { my $p; $b <=> $a } 1,4,3
141>>>>
142431