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 | |
82a7479c |
67 | ../t/op/switch.t |
68 | |
69 | ../t/op/attrhand.t |
70 | |
71 | ../t/op/symbolcache.t |
72 | |
b3f5cf18 |
73 | ../t/op/exec.t |
58a97135 |
74 | |
58a97135 |
75 | ../t/op/state.t |
58a97135 |
76 | ../t/op/each_array.t |
58a97135 |
77 | ../t/lib/cygwin.t |
82a7479c |
78 | |; |
79 | |
80 | my @files; |
81 | find( sub { push @files, $File::Find::name if m/[.]t$/ }, '../t/'); |
82 | |
83 | for my $file (@files) { |
84 | my $input; |
85 | local $/ = undef; |
86 | local $TODO = (exists $failing{$file} ? "Known failure" : undef); |
87 | #warn $file; |
88 | open(my $fh, "<", "$file") or die "Failed open '../t/$file' $!"; |
89 | $input = $fh->getline; |
90 | close $fh or die; |
91 | |
92 | my $switches = ""; |
93 | if( $input =~ m/^[#][!].*perl(.*)/) { |
94 | $switches = $1; |
95 | } |
96 | |
97 | unlink "tmp.xml"; |
98 | `PERL_XMLDUMP='tmp.xml' ../perl $switches -I ../lib $file 2> tmp.err`; |
99 | |
100 | if (-z "tmp.xml") { |
101 | fail "MAD dump failure of '$file'"; |
102 | next; |
103 | } |
104 | my $output = eval { Nomad::xml_to_p5( input => "tmp.xml" ) }; |
105 | if ($@) { |
106 | fail "convert xml to p5 failed file: '$file'"; |
107 | diag "error: $@"; |
108 | next; |
109 | } |
110 | eq_or_diff $output, $input, "p55 '$file'"; |
111 | } |
112 | |
113 | __DATA__ |
114 | use strict; |
115 | #ABC |
116 | new Foo; |
117 | Foo->new; |
118 | ######## |
119 | sub pi() { 3.14 } |
120 | my $x = pi; |
121 | ######## |
122 | -OS_Code => $a |
123 | ######## |
124 | use encoding 'euc-jp'; |
125 | tr/¤¡-¤ó¥¡-¥ó/¥¡-¥ó¤¡-¤ó/; |
126 | ######## |
127 | sub ok($$) { } |
128 | BEGIN { ok(1, 2, ); } |
129 | ######## |
130 | for (my $i=0; $i<3; $i++) { } |
131 | ######## |
132 | for (; $a<3; $a++) { } |
133 | ######## |
b3f5cf18 |
134 | # |
82a7479c |
135 | s//$#foo/ge; |
136 | ######## |
b3f5cf18 |
137 | # |
82a7479c |
138 | s//m#.#/ge; |
139 | ######## |
b3f5cf18 |
140 | # |
82a7479c |
141 | eval { require 5.005 } |
142 | ######## |
c631f32b |
143 | # Reduced test case from t/io/layers.t |
82a7479c |
144 | sub PerlIO::F_UTF8 () { 0x00008000 } # from perliol.h |
145 | BEGIN { PerlIO::Layer->find("encoding",1);} |
146 | ######## |
27aaedc1 |
147 | # from ../t/op/array.t |
82a7479c |
148 | $[ = 1 |
149 | ######## |
27aaedc1 |
150 | # from t/comp/parser.t |
82a7479c |
151 | $x = 1 for ($[) = 0; |
152 | ######## |
d5d3e0f0 |
153 | # from t/op/getppid.t |
82a7479c |
154 | pipe my ($r, $w) |
155 | ######## |
156 | # TODO switch |
157 | use feature 'switch'; |
158 | given(my $x = "bar") { } |
159 | ######## |
160 | # TODO attribute t/op/attrhand.t |
161 | sub something : TypeCheck( |
162 | QNET::Util::Object, |
163 | QNET::Util::Object, |
164 | QNET::Util::Object |
165 | ) { # WrongAttr (perl tokenizer bug) |
166 | # keep this ^ lined up ! |
167 | return 42; |
168 | } |
169 | ######## |
170 | # TODO symbol table t/op/symbolcache.t |
171 | sub replaced2 { 'func' } |
172 | BEGIN { undef $main::{replaced2} } |
173 | ######## |
174 | # TODO exit in begin block. from t/op/threads.t without threads |
175 | BEGIN { |
176 | exit 0; |
177 | } |
178 | use foobar; |