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
|
BEGIN {
if($ENV{PERL_CORE}) {
chdir 't';
@INC = '../lib';
} else {
push @INC, '../lib';
}
}
use strict;
use Test;
BEGIN { plan tests => 26 };
use Pod::Simple::TextContent;
use Pod::Simple::Text;
BEGIN {
*mytime = defined(&Win32::GetTickCount)
? sub () {Win32::GetTickCount() / 1000}
: sub () {time()}
}
$Pod::Simple::Text::FREAKYMODE = 1;
use Pod::Simple::TiedOutFH ();
chdir 't' unless $ENV{PERL_CORE};
sub source_path {
my $file = shift;
if ($ENV{PERL_CORE}) {
require File::Spec;
my $updir = File::Spec->updir;
my $dir = File::Spec->catdir ($updir, 'lib', 'Pod', 'Simple', 't');
return File::Spec->catfile ($dir, $file);
} else {
return $file;
}
}
my $outfile = '10000';
foreach my $file (
"junk1.pod",
"junk2.pod",
"perlcyg.pod",
"perlfaq.pod",
"perlvar.pod",
) {
unless(-e source_path($file)) {
ok 0;
print "# But $file doesn't exist!!\n";
exit 1;
}
my @out;
my $precooked = source_path($file);
$precooked =~ s<\.pod><o.txt>s;
unless(-e $precooked) {
ok 0;
print "# But $precooked doesn't exist!!\n";
exit 1;
}
print "#\n#\n#\n###################\n# $file\n";
foreach my $class ('Pod::Simple::TextContent', 'Pod::Simple::Text') {
my $p = $class->new;
push @out, '';
$p->output_string(\$out[-1]);
my $t = mytime();
$p->parse_file(source_path($file));
printf "# %s %s %sb, %.03fs\n",
ref($p), source_path($file), length($out[-1]), mytime() - $t ;
ok 1;
}
print "# Reading $precooked...\n";
open(IN, $precooked) or die "Can't read-open $precooked: $!";
{
local $/;
push @out, <IN>;
}
close(IN);
print "# ", length($out[-1]), " bytes pulled in.\n";
for (@out) { s/\s+/ /g; s/^\s+//s; s/\s+$//s; }
my $faily = 0;
print "#\n#Now comparing 1 and 2...\n";
$faily += compare2($out[0], $out[1]);
print "#\n#Now comparing 2 and 3...\n";
$faily += compare2($out[1], $out[2]);
print "#\n#Now comparing 1 and 3...\n";
$faily += compare2($out[0], $out[2]);
if($faily) {
++$outfile;
my @outnames = map $outfile . $_ , qw(0 1);
open(OUT2, ">$outnames[0].~out.txt") || die "Can't write-open $outnames[0].txt: $!";
foreach my $out (@out) { push @outnames, $outnames[-1]; ++$outnames[-1] };
pop @outnames;
printf "# Writing to %s.txt .. %s.txt\n", $outnames[0], $outnames[-1];
shift @outnames;
binmode(OUT2);
foreach my $out (@out) {
my $outname = shift @outnames;
open(OUT, ">$outname.txt") || die "Can't write-open $outname.txt: $!";
binmode(OUT);
print OUT $out, "\n";
print OUT2 $out, "\n";
close(OUT);
}
close(OUT2);
}
}
print "# Wrapping up... one for the road...\n";
ok 1;
print "# --- Done with ", __FILE__, " --- \n";
exit;
sub compare2 {
my @out = @_;
if($out[0] eq $out[1]) {
ok 1;
return 0;
} elsif( do{
for ($out[0], $out[1]) { tr/ //d; };
$out[0] eq $out[1];
}){
print "# Differ only in whitespace.\n";
ok 1;
return 0;
} else {
#ok $out[0], $out[1];
my $x = $out[0] ^ $out[1];
$x =~ m/^(\x00*)/s or die;
my $at = length($1);
print "# Difference at byte $at...\n";
if($at > 10) {
$at -= 5;
}
{
print "# ", substr($out[0],$at,20), "\n";
print "# ", substr($out[1],$at,20), "\n";
print "# ^...";
}
ok 0;
printf "# Unequal lengths %s and %s\n", length($out[0]), length($out[1]);
return 1;
}
}
__END__
|