6 @INC = qw(: ::lib ::macos:lib);
21 my $deparse = B::Deparse->new() or print "not ";
23 print "ok " . $i++ . "\n";
26 # Tell B::Deparse about our ambient pragmas
27 { my ($hint_bits, $warning_bits);
28 BEGIN { ($hint_bits, $warning_bits) = ($^H, ${^WARNING_BITS}); }
29 $deparse->ambient_pragmas (
30 hint_bits => $hint_bits,
31 warning_bits => $warning_bits,
41 my ($input, $expected);
42 if (/(.*)\n>>>>\n(.*)/s) {
43 ($input, $expected) = ($1, $2);
46 ($input, $expected) = ($_, $_);
49 my $coderef = eval "sub {$input}";
52 print "not ok " . $i++ . "\n";
56 my $deparsed = $deparse->coderef2text( $coderef );
57 my $regex = quotemeta($expected);
60 $regex =~ s/\s+/\s+/g;
63 my $ok = ($deparsed =~ /^\{\s*$regex\s*\}$/);
64 print (($ok ? "ok " : "not ok ") . $i++ . "\n");
66 print "# EXPECTED:\n";
71 $deparsed =~ s/^/# /mg;
77 use constant 'c', 'stuff';
78 print "not " if (eval "sub ".$deparse->coderef2text(\&c))->() ne 'stuff';
79 print "ok " . $i++ . "\n";
82 print "not " if "{\n (-1) ** \$a;\n}"
83 ne $deparse->coderef2text(sub{(-1) ** $a });
84 print "ok " . $i++ . "\n";
86 # XXX ToDo - constsub that returns a reference
87 #use constant cr => ['hello'];
88 #my $string = "sub " . $deparse->coderef2text(\&cr);
89 #my $val = (eval $string)->();
90 #print "not " if ref($val) ne 'ARRAY' || $val->[0] ne 'hello';
91 #print "ok " . $i++ . "\n";
94 my $Is_VMS = $^O eq 'VMS';
95 my $Is_MacOS = $^O eq 'MacOS';
97 my $path = join " ", map { qq["-I$_"] } @INC;
98 $path .= " -MMac::err=unix" if $Is_MacOS;
99 my $redir = $Is_MacOS ? "" : "2>&1";
101 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 $redir`;
102 $a =~ s/-e syntax OK\n//g;
103 $a =~ s/.*possible typo.*\n//; # Remove warning line
104 $a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
105 $a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
107 BEGIN { $^I = ".bak"; }
109 BEGIN { $/ = "\n"; $\ = "\n"; }
110 LINE: while (defined($_ = <ARGV>)) {
112 our(@F) = split(" ", $_, 0);
116 $b =~ s/(LINE:)/sub BEGIN {
117 'MacPerl'->bootstrap;
122 print "# [$a]\n\# vs expected\n# [$b]\nnot " if $a ne $b;
123 print "ok " . $i++ . "\n";
138 ++$test and $test /= 2;
141 $test /= 2 if ++$test;
148 my $test = sub : lvalue {
156 my $test = sub : method {
164 my $test = sub : locked method {
192 $_ .= <ARGV> . <$foo>;
195 my $foo = "Ab\x{100}\200\x{200}\377Cd\000Ef\x{1000}\cA\x{2000}\cZ";