test for B::Bytecode/ByteLoader
authorAdrian M. Enache <enache@rdslink.ro>
Thu, 31 Jul 2003 03:49:40 +0000 (06:49 +0300)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 31 Jul 2003 05:06:11 +0000 (05:06 +0000)
Message-ID: <20030731004940.GB1266@ratsnest.hole>

(but use test.pl:run_perl() instead of manual `$^X ...`)

p4raw-id: //depot/perl@20366

MANIFEST
ext/B/t/bytecode.t [new file with mode: 0644]

index 4a85968..4951fa6 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -109,6 +109,7 @@ ext/B/t/asmdata.t   See if B::Asmdata works
 ext/B/t/assembler.t    See if B::Assembler, B::Disassembler comply
 ext/B/t/b.t            See if B works
 ext/B/t/bblock.t       See if B::Bblock works
+ext/B/t/bytecode.t     See whether B::Bytecode works
 ext/B/t/concise.t      See whether B::Concise works
 ext/B/t/debug.t                See if B::Debug works
 ext/B/t/deparse.t      See if B::Deparse works
diff --git a/ext/B/t/bytecode.t b/ext/B/t/bytecode.t
new file mode 100644 (file)
index 0000000..4ac8652
--- /dev/null
@@ -0,0 +1,145 @@
+#!./perl
+
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = qw(../lib);
+    require './test.pl'; # for run_perl()
+}
+use strict;
+
+my $test = 'bytecode.pl';
+END { 1 while unlink $test }
+
+undef $/;
+my @tests = split /\n###+\n/, <DATA>;
+
+print "1..".($#tests+1)."\n";
+
+my $cnt = 1;
+
+for (@tests) {
+    my $got;
+    my ($script, $expect) = split />>>+\n/;
+    $expect =~ s/\n$//;
+    open T, ">$test"; print T $script; close T;
+    $got = run_perl(switches => "-MO=Bytecode,-H,-o$test",
+                   progfile => $test);
+    unless ($?) {
+       $got = run_perl(progfile => $test);
+       unless ($?) {
+           if ($got =~ /^$expect$/) {
+               print "ok $cnt\n";
+               next;
+           } else {
+               print <<"EOT"; next;
+not ok $cnt
+--------- SCRIPT
+$script
+--------- GOT
+$got
+--------- EXPECT
+$expect
+----------------
+
+EOT
+           }
+       }
+    }
+    print <<"EOT";
+--------- SCRIPT
+$script
+--------- $?
+$got
+EOT
+} continue {
+    $cnt++;
+}
+
+__DATA__
+
+print 'hi'
+>>>>
+hi
+############################################################
+for (1,2,3) { print if /\d/ }
+>>>>
+123
+############################################################
+$_ = "xyxyx"; %j=(1,2); s/x/$j{print('z')}/ge; print $_
+>>>>
+zzz2y2y2
+############################################################
+$_ = "xyxyx"; %j=(1,2); s/x/$j{print('z')}/g; print $_
+>>>>
+z2y2y2
+############################################################
+split /a/,"bananarama"; print @_
+>>>>
+bnnrm
+############################################################
+{ package P; sub x { print 'ya' } x }
+>>>>
+ya
+############################################################
+@z = split /:/,"b:r:n:f:g"; print @z
+>>>>
+brnfg
+############################################################
+sub AUTOLOAD { print 1 } &{"a"}()
+>>>>
+1
+############################################################
+my $l = 3; $x = sub { print $l }; &$x
+>>>>
+3
+############################################################
+my $i = 1;
+my $foo = sub {$i = shift if @_};
+&$foo(3);
+############################################################
+print <.*>
+>>>>
+..*
+############################################################
+$_="\xff\xff"; use utf8; utf8::encode $_; print $_
+>>>>
+\xc3\xbf\xc3\xbf
+############################################################
+$x="Cannot use"; print index $x, "Can"
+>>>>
+0
+############################################################
+my $i=6; eval "print \$i\n"
+>>>>
+6
+############################################################
+BEGIN { %h=(1=>2,3=>4) } print $h{3}
+>>>>
+4
+############################################################
+open our $T,"a"
+############################################################
+print <DATA>
+__DATA__
+a
+b
+>>>>
+a
+b
+############################################################
+BEGIN { tie @a, __PACKAGE__; sub TIEARRAY { bless{} } sub FETCH { 1 } }
+print $a[1]
+>>>>
+1
+############################################################
+my $i=3; print 1 .. $i
+>>>>
+123
+############################################################
+my $h = { a=>3, b=>1 }; print sort {$h->{$a} <=> $h->{$b}} keys %$h
+>>>>
+ba
+############################################################
+print sort { my $p; $b <=> $a } 1,4,3
+>>>>
+431