7 @INC = qw(: ::lib ::macos:lib);
16 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
17 print "1..0 # Skip -- Perl configured without B module\n";
25 use Test::More tests => 54;
28 my $deparse = B::Deparse->new();
31 # Tell B::Deparse about our ambient pragmas
32 { my ($hint_bits, $warning_bits, $hinthash);
33 BEGIN { ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H); }
34 $deparse->ambient_pragmas (
35 hint_bits => $hint_bits,
36 warning_bits => $warning_bits,
46 my ($num, $testname) = $1 =~ m/(\d+)\s*(.*)/;
47 my ($input, $expected);
48 if (/(.*)\n>>>>\n(.*)/s) {
49 ($input, $expected) = ($1, $2);
52 ($input, $expected) = ($_, $_);
55 my $coderef = eval "sub {$input}";
58 diag("$num deparsed: $@");
62 my $deparsed = $deparse->coderef2text( $coderef );
63 my $regex = $expected;
64 $regex =~ s/(\S+)/\Q$1/g;
65 $regex =~ s/\s+/\\s+/g;
66 $regex = '^\{\s*' . $regex . '\s*\}$';
67 like($deparsed, qr/$regex/, $testname);
71 use constant 'c', 'stuff';
72 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff');
75 is("{\n (-1) ** \$a;\n}", $deparse->coderef2text(sub{(-1) ** $a }));
77 use constant cr => ['hello'];
78 my $string = "sub " . $deparse->coderef2text(\&cr);
79 my $val = (eval $string)->();
80 ok( ref($val) eq 'ARRAY' && $val->[0] eq 'hello');
82 my $Is_VMS = $^O eq 'VMS';
83 my $Is_MacOS = $^O eq 'MacOS';
85 my $path = join " ", map { qq["-I$_"] } @INC;
86 $path .= " -MMac::err=unix" if $Is_MacOS;
87 my $redir = $Is_MacOS ? "" : "2>&1";
89 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 $redir`;
90 $a =~ s/-e syntax OK\n//g;
91 $a =~ s/.*possible typo.*\n//; # Remove warning line
92 $a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
93 $a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
95 BEGIN { $^I = ".bak"; }
97 BEGIN { $/ = "\n"; $\ = "\n"; }
98 LINE: while (defined($_ = <ARGV>)) {
100 our(@F) = split(' ', $_, 0);
104 $b =~ s/(LINE:)/sub BEGIN {
105 'MacPerl'->bootstrap;
112 #Re: perlbug #35857, patch #24505
113 #handle warnings::register-ed packages properly.
114 package B::Deparse::Wrapper;
117 use warnings::register;
119 my $deparser = B::Deparse->new();
120 return $deparser->coderef2text(shift);
128 my $res = B::Deparse::Wrapper::getcode($val);
129 like( $res, qr/use warnings/);
132 my $x=sub { ++$q,++$p };
134 eval <<EOFCODE and test($x);
138 use warnings::register;
156 ++$test and $test /= 2;
159 $test /= 2 if ++$test;
166 my $test = sub : lvalue {
174 my $test = sub : method {
182 my $test = sub : locked method {
210 $_ .= <ARGV> . <$foo>;
213 my $foo = "Ab\x{100}\200\x{200}\377Cd\000Ef\x{1000}\cA\x{2000}\cZ";
218 # 16 - various lypes of loop
232 for (my $i = 0; $i < 2;) {
237 for (my $i = 0; $i < 2; ++$i) {
242 for (my $i = 0; $i < 2; ++$i) {
248 while ($i) { my $z = 1; } continue { $i = 99; }
251 foreach my $i (1, 2) {
263 foreach my $i (1, 2) {
268 foreach my $i (1, 2) {
273 foreach our $i (1, 2) {
279 foreach our $i (1, 2) {
285 print reverse sort(@x);
289 print((sort {$b cmp $a} @x));
293 print((reverse sort {$b <=> $a} @x));
297 print $_ foreach (reverse @a);
301 print $_ foreach (reverse 1, 2..5);
305 @ary = split(' ', 'foo', 0);
311 do { my $x = 1; $x };
313 # 37 <20061012113037.GJ25805@c4.convolution.nl>
346 # 47 state var assignment
348 my $y = (state $x = 42);
351 # 48 state vars in anoymous subroutines