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