1 # Testing a corpus of Pod files
9 if ($Config::Config{'extensions'} !~ /\bEncode\b/) {
10 print "1..0 # Skip: Encode was not built\n";
15 #use Pod::Simple::Debug (10);
16 use Test qw(plan ok skip);
21 my(@testfiles, %xmlfiles, %wouldxml);
22 #use Pod::Simple::Debug (10);
27 if ($ENV{PERL_CORE}) {
29 my $updir = File::Spec->updir;
30 my $dir = File::Spec->catdir($updir, 'lib', 'Pod', 'Simple', 't');
31 return File::Spec->catdir ($dir, $file);
37 if(-e( File::Spec::->catdir( @bits =
38 source_path('corpus') ) ) )
41 print "# 1Bits: @bits\n";
42 } elsif( -e (File::Spec::->catdir( @bits =
43 (File::Spec::->curdir, 'corpus') ) )
46 print "# 2Bits: @bits\n";
47 } elsif ( -e (File::Spec::->catdir( @bits =
48 (File::Spec::->curdir, 't', 'corpus') ) )
51 print "# 3Bits: @bits\n";
53 die "Can't find the corpusdir";
55 my $corpusdir = File::Spec::->catdir( @bits);
56 print "#Corpusdir: $corpusdir\n";
58 opendir(INDIR, $corpusdir) or die "Can't opendir corpusdir : $!";
59 my @f = map File::Spec::->catfile(@bits, $_), readdir(INDIR);
63 foreach my $maybetest (sort @f) {
65 $xml =~ s/\.(txt|pod)$/\.xml/is or next;
66 $wouldxml{$maybetest} = $xml;
67 push @testfiles, $maybetest;
68 foreach my $x ($xml, uc($xml), lc($xml)) {
69 next unless exists $f{$x};
70 $xmlfiles{$maybetest} = $x;
74 die "Too few test files (".@testfiles.")" unless @ARGV or @testfiles > 20;
76 @testfiles = @ARGV if @ARGV and !grep !m/\.txt/, @ARGV;
78 plan tests => (2 + 2*@testfiles - 1);
82 #@testfiles = ('nonesuch.txt');
86 my $skippy = ($] < 5.008) ? "skip because perl ($]) pre-dates v5.8.0" : 0;
88 print "# This is just perl v$], so I'm skipping many many tests.\n";
93 print "# Files to test:\n";
94 while(@x) { print "# ", join(' ', splice @x,0,3), "\n" }
97 require Pod::Simple::DumpAsXML;
100 foreach my $f (@testfiles) {
101 my $xml = $xmlfiles{$f};
103 print "#\n#To test $f against $xml\n";
105 print "#\n# $f has no xml to test it against\n";
110 my $p = Pod::Simple::DumpAsXML->new;
111 $p->output_string( \$outstring );
112 $p->parse_file( $f );
117 my $x = "#** Couldn't parse $f:\n $@";
118 $x =~ s/([\n\r]+)/\n#** /g;
124 print "# OK, parsing $f generated ", length($outstring), " bytes\n";
128 die "Null outstring?" unless $outstring;
130 next if $f =~ /nonesuch/;
132 my $outfilename = ($HACK > 1) ? $wouldxml{$f} : "$wouldxml{$f}\_out";
134 open OUT, ">$outfilename" or die "Can't write-open $outfilename: $!\n";
136 print OUT $outstring;
140 print "# (no comparison done)\n";
145 open(IN, "<$xml") or die "Can't read-open $xml: $!";
148 my $xmlsource = <IN>;
151 print "# There's errata!\n" if $outstring =~ m/start_line="-321"/;
154 $xmlsource eq $outstring
156 $xmlsource =~ s/[\n\r]+/\n/g;
157 $outstring =~ s/[\n\r]+/\n/g;
158 $xmlsource eq $outstring;
161 print "# (Perfect match to $xml)\n";
162 unlink $outfilename unless $outfilename =~ m/\.xml$/is;
170 print "# $outfilename and $xml don't match!\n";
177 print "#\n# I've been using Encode v",
178 $Encode::VERSION ? $Encode::VERSION : "(NONE)", "\n";
181 print "# --- Done with ", __FILE__, " --- \n";