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