1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# Test p55, the "Perl 5 to Perl 5" translator.
# The perl core should have MAD enabled ('sh Configure -Dmad=y ...')
# The part to convert xml to Perl 5 requires XML::Parser, but it does
# not depend on Perl internals, so you can use a stable system wide
# perl
# For the p55 on the perl test suite, it should be started from the
# $perlsource/t subdir
# Instructions:
# sh Configure -Dmad=y
# make && make test
# cd t && /usr/bin/prove ../mad/t/p55.t
use strict;
use warnings;
BEGIN {
push @INC, "../mad";
}
use Test::More qw|no_plan|;
use IO::Handle;
use Nomad;
sub p55 {
my ($input, $msg) = @_;
# perl5 to xml
open my $infile, "> tmp.in";
$infile->print($input);
close $infile;
unlink "tmp.xml";
`PERL_XMLDUMP='tmp.xml' ../perl -I ../lib tmp.in 2> tmp.err`;
if (-z "tmp.xml") {
return ok 0, "MAD dump failed $msg";
}
my $output = eval { Nomad::xml_to_p5( input => "tmp.xml" ) };
diag($@) if $@;
is($output, $input, $msg);
}
undef $/;
my @prgs = split m/^########\n/m, <DATA>;
use bytes;
for my $prog (@prgs) {
my $msg = ($prog =~ s/^#(.*)\n//) && $1;
local $TODO = ($msg =~ /TODO/) ? 1 : 0;
p55($prog, $msg);
}
# Files
use File::Find;
use Test::Differences;
our %failing = map { $_, 1 } qw|
../t/comp/require.t
../t/io/layers.t
../t/op/array.t
../t/op/local.t
../t/op/substr.t
../t/comp/parser.t
../t/op/getppid.t
../t/op/switch.t
../t/op/attrhand.t
../t/op/symbolcache.t
../t/op/threads.t
../t/op/exec.t
../t/io/say.t
|;
my @files;
find( sub { push @files, $File::Find::name if m/[.]t$/ }, '../t/');
for my $file (@files) {
my $input;
local $/ = undef;
local $TODO = (exists $failing{$file} ? "Known failure" : undef);
#warn $file;
open(my $fh, "<", "$file") or die "Failed open '../t/$file' $!";
$input = $fh->getline;
close $fh or die;
my $switches = "";
if( $input =~ m/^[#][!].*perl(.*)/) {
$switches = $1;
}
unlink "tmp.xml";
`PERL_XMLDUMP='tmp.xml' ../perl $switches -I ../lib $file 2> tmp.err`;
if (-z "tmp.xml") {
fail "MAD dump failure of '$file'";
next;
}
my $output = eval { Nomad::xml_to_p5( input => "tmp.xml" ) };
if ($@) {
fail "convert xml to p5 failed file: '$file'";
diag "error: $@";
next;
}
eq_or_diff $output, $input, "p55 '$file'";
}
__DATA__
use strict;
#ABC
new Foo;
Foo->new;
########
sub pi() { 3.14 }
my $x = pi;
########
-OS_Code => $a
########
use encoding 'euc-jp';
tr/¤¡-¤ó¥¡-¥ó/¥¡-¥ó¤¡-¤ó/;
########
sub ok($$) { }
BEGIN { ok(1, 2, ); }
########
for (my $i=0; $i<3; $i++) { }
########
for (; $a<3; $a++) { }
########
#
s//$#foo/ge;
########
#
s//m#.#/ge;
########
#
eval { require 5.005 }
########
# TODO Reduced test case from t/io/layers.t
sub PerlIO::F_UTF8 () { 0x00008000 } # from perliol.h
BEGIN { PerlIO::Layer->find("encoding",1);}
########
# TODO from ../t/op/array.t
$[ = 1
########
# TODO from t/comp/parser.t
$x = 1 for ($[) = 0;
########
# TODO from t/op/getppid.t
pipe my ($r, $w)
########
# TODO switch
use feature 'switch';
given(my $x = "bar") { }
########
# TODO attribute t/op/attrhand.t
sub something : TypeCheck(
QNET::Util::Object,
QNET::Util::Object,
QNET::Util::Object
) { # WrongAttr (perl tokenizer bug)
# keep this ^ lined up !
return 42;
}
########
# TODO symbol table t/op/symbolcache.t
sub replaced2 { 'func' }
BEGIN { undef $main::{replaced2} }
########
# TODO exit in begin block. from t/op/threads.t without threads
BEGIN {
exit 0;
}
use foobar;
|