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
|
# Testing Pod::Simple::JustPod against *.pod in /t
use strict;
BEGIN {
if($ENV{PERL_CORE}) {
chdir 't';
@INC = '../lib';
}
use Config;
if ($Config::Config{'extensions'} !~ /\bEncode\b/) {
print "1..0 # Skip: Encode was not built\n";
exit 0;
}
}
use File::Find;
use File::Spec;
use Test::More;
use Pod::Simple::JustPod;
my @test_files;
BEGIN {
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->catdir($dir, $file);
}
else {
return $file;
}
}
my @test_dirs = (
File::Spec->catdir( source_path('t') ) ,
File::Spec->catdir( File::Spec->updir, 't') ,
);
my $test_dir;
foreach( @test_dirs ) {
$test_dir = $_ and last if -e;
}
die "Can't find the test dir" unless $test_dir;
print "# TESTDIR: $test_dir\n";
sub wanted {
push @test_files, $File::Find::name
if $File::Find::name =~ /\.pod$/;
}
find(\&wanted , $test_dir );
plan tests => scalar @test_files;
}
foreach my $file (@test_files) {
my $parser = Pod::Simple::JustPod->new();
$parser->complain_stderr(0);
my $input;
open( IN , '<:raw' , $file ) or die "$file: $!";
$input .= $_ while (<IN>);
close( IN );
my $output;
$parser->output_string( \$output );
$parser->parse_string_document( $input );
if ($parser->any_errata_seen()) {
pass("Skip '$file' because of pod errors");
next if "$]" lt '5.010.001'; # note() not found in earlier versions
my $errata = $parser->errata_seen();
foreach my $line_number (sort { $a <=> $b } keys %$errata) {
foreach my $err_msg (sort @{$errata->{$line_number}}) {
note("$file: $line_number: $err_msg");
}
}
next;
}
my $encoding = $parser->encoding();
if (defined $encoding) {
eval { require Encode; };
$input = Encode::decode($parser->encoding(), $input);
}
my @input = split "\n", $input;
my $stripped_input = "";
while (defined ($_ = shift @input)) {
if (/ ^ = [a-z]+ /x) {
my $line = "$_\n";
if ($stripped_input eq "" || $_ !~ /^=pod/) {
$stripped_input .= $line;
}
while (defined ($_ = shift @input)) {
$stripped_input .= "$_\n";
last if / ^ =cut /x;
}
}
}
$stripped_input =~ s/ ^ =cut \n (.) /$1/mgx;
$input = $stripped_input if $stripped_input ne "";
if ($input !~ / ^ =pod /x) {
$input =~ s/ ^ \s+ //x;
$input = "=pod\n\n$input";
}
if ($input !~ / =cut $ /x) {
$input =~ s/ \s+ $ //x;
$input .= "\n\n=cut\n";
}
my $msg = "got expected output for $file";
if ($output eq $input) {
pass($msg);
}
elsif ($ENV{PERL_TEST_DIFF}) {
fail($msg);
require File::Temp;
my $orig_file = File::Temp->new();
local $/ = "\n";
chomp $input;
print $orig_file $input, "\n";
close $orig_file || die "Can't close orig_file: $!";
chomp $output;
my $parsed_file = File::Temp->new();
print $parsed_file $output, "\n";
close $parsed_file || die "Can't close parsed_file";
my $diff = File::Temp->new();
system("$ENV{PERL_TEST_DIFF} $orig_file $parsed_file > $diff");
open my $fh, "<", $diff || die "Can't open $diff";
my @diffs = <$fh>;
diag(@diffs);
}
else {
eval { require Text::Diff; };
if ($@) {
is($output, $input, $msg);
diag("Set environment variable PERL_TEST_DIFF=diff_tool or install"
. " Text::Diff to see just the differences.");
}
else {
fail($msg);
diag Text::Diff::diff(\$input, \$output, { STYLE => 'Unified' });
}
}
}
|