add testsuite for B backends, fix bug in B::Deparse (from
[p5sagit/p5-mst-13.2.git] / t / lib / b.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     unshift @INC, '../lib';
6 }
7
8 $|  = 1;
9 use warnings;
10 use strict;
11 use Config;
12
13 print "1..10\n";
14
15 my $test = 1;
16
17 sub ok { print "ok $test\n"; $test++ }
18
19 use B::Deparse;
20 my $deparse = B::Deparse->new() or print "not ";
21 ok;
22
23 print "not " if "{\n    1;\n}" ne $deparse->coderef2text(sub {1});
24 ok;
25
26 print "not " if "{\n    '???';\n    2;\n}" ne
27                     $deparse->coderef2text(sub {1;2});
28 ok;
29
30 print "not " if "{\n    \$test /= 2 if ++\$test;\n}" ne
31                     $deparse->coderef2text(sub {++$test and $test/=2;});
32 ok;
33
34 my $a = `$^X -I../lib -MO=Deparse -anle 1 2>&1`;
35 $b = <<'EOF';
36 -e syntax OK
37
38 LINE: while (defined($_ = <ARGV>)) {
39     chomp $_;
40     @F = split(/\s+/, $_, 0);
41     '???'
42 }
43 continue {
44     '???'
45 }
46
47 EOF
48 print "not " if $a ne $b;
49 ok;
50
51 #6
52 $a = `$^X -I../lib -MO=Debug -e 1 2>&1`;
53 print "not " unless $a =~
54 /\bLISTOP\b.*\bOP\b.*\bCOP\b.*\bOP\b/s;
55 ok;
56
57 #7
58 $a = `$^X -I../lib -MO=Terse -e 1 2>&1`;
59 print "not " unless $a =~
60 /\bLISTOP\b.*leave.*\bOP\b.*enter.*\bCOP\b.*nextstate.*\bOP\b.*null/s;
61 ok;
62
63 $a = `$^X -I../lib -MO=Terse -ane 's/foo/bar/' 2>&1`;
64 $a =~ s/\(0x[^)]+\)//g;
65 $a =~ s/\[[^\]]+\]//g;
66 $a =~ s/-e syntax OK//;
67 $a =~ s/[^a-z ]+//g;
68 $a =~ s/\s+/ /g;
69 $a =~ s/\b(s|foo|ullsv)\b\s?//g;
70 $a =~ s/^\s+//;
71 $a =~ s/\s+$//;
72 $b=<<EOF;
73 leave enter nextstate label leaveloop enterloop null and defined null
74 null gvsv readline gv lineseq nextstate aassign null pushmark split pushre
75 null gvsv const null pushmark rvav gv nextstate subst const unstack
76 nextstate
77 EOF
78 $b=~s/\n/ /g;$b=~s/\s+/ /g;
79 $b =~ s/\s+$//;
80 print "# [$a] vs [$b]\nnot " if $a ne $b;
81 ok;
82
83 chomp($a = `$^X -I../lib -MB::Stash -Mwarnings -e1`);
84 $a = join ',', sort split /,/, $a;
85 $b = '-uCarp,-uCarp::Heavy,-uDB,-uExporter,-uExporter::Heavy,-uattributes,'
86    . '-umain,-uwarnings';
87 print "# [$a] vs [$b]\nnot " if $a ne $b;
88 ok;
89
90 $a = `$^X -I../lib -MO=Showlex -e "my %one" 2>&1`;
91 print "# [$a]\nnot " unless $a =~ /sv_undef.*PVNV.*%one.*sv_undef.*HV/s;
92 ok;