1 package TestPodIncPlainText;
8 my $THISDIR = abs_path(dirname $0);
9 unshift @INC, $THISDIR;
12 my $PARENTDIR = dirname $THISDIR;
13 push @INC, map { File::Spec->catfile($_, 'lib') } ($PARENTDIR, $THISDIR);
21 #use Cwd qw(abs_path);
23 use vars qw($MYPKG @EXPORT @ISA);
24 $MYPKG = eval { (caller)[0] };
25 @EXPORT = qw(&testpodplaintext);
27 if ( $] >= 5.005_58 ) {
29 @ISA = qw( Pod::Text );
32 require Pod::PlainText;
33 @ISA = qw( Pod::PlainText );
35 require VMS::Filespec if $^O eq 'VMS';
38 ## Hardcode settings for TERMCAP and COLUMNS so we can try to get
39 ## reproducible results between environments
40 @ENV{qw(TERMCAP COLUMNS)} = ('co=76:do=^J', 76);
42 sub catfile(@) { File::Spec->catfile(@_); }
44 my $INSTDIR = abs_path(dirname $0);
45 $INSTDIR = VMS::Filespec::unixpath($INSTDIR) if $^O eq 'VMS';
46 $INSTDIR =~ s#/$## if $^O eq 'VMS';
47 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 'xtra');
48 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 'pod');
49 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 't');
50 my @PODINCDIRS = ( catfile($INSTDIR, 'lib', 'Pod'),
51 catfile($INSTDIR, 'pod'),
52 catfile($INSTDIR, 't', 'pod'),
53 catfile($INSTDIR, 't', 'pod', 'xtra')
56 ## Find the path to the file to =include
61 ## See if its already found w/out any "searching;
62 return $incname if (-r $incname);
64 ## Need to search for it. Look in the following directories ...
65 ## 1. the directory containing this pod file
66 my $thispoddir = dirname $self->input_file;
67 ## 2. the parent directory of the above
68 my $parentdir = dirname $thispoddir;
69 my @podincdirs = ($thispoddir, $parentdir, @PODINCDIRS);
72 my $incfile = catfile($_, $incname);
73 return $incfile if (-r $incfile);
75 warn("*** Can't find =include file $incname in @podincdirs\n");
81 my ($cmd, $text, $line_num, $pod_para) = @_;
82 $cmd = '' unless (defined $cmd);
83 local $_ = $text || '';
84 my $out_fh = $self->output_handle;
86 ## Defer to the superclass for everything except '=include'
87 return $self->SUPER::command(@_) unless ($cmd eq "include");
89 ## We have an '=include' command
90 my $incdebug = 1; ## debugging
93 warn("*** No filename given for '=include'\n");
96 my $incfile = $self->findinclude(shift @incargs) or return;
97 my $incbase = basename $incfile;
98 print $out_fh "###### begin =include $incbase #####\n" if ($incdebug);
99 $self->parse_from_file( {-cutting => 1}, $incfile );
100 print $out_fh "###### end =include $incbase #####\n" if ($incdebug);
103 sub podinc2plaintext( $ $ ) {
104 my ($infile, $outfile) = @_;
106 my $text_parser = $MYPKG->new;
107 $text_parser->parse_from_file($infile, $outfile);
110 sub testpodinc2plaintext( @ ) {
112 my $infile = $args{'-In'} || croak "No input file given!";
113 my $outfile = $args{'-Out'} || croak "No output file given!";
114 my $cmpfile = $args{'-Cmp'} || croak "No compare-result file given!";
117 my $testname = basename $cmpfile, '.t', '.xr';
119 unless (-e $cmpfile) {
120 my $msg = "*** Can't find comparison file $cmpfile for testing $infile";
125 print "# Running testpodinc2plaintext for '$testname'...\n";
126 ## Compare the output against the expected result
127 podinc2plaintext($infile, $outfile);
128 if ( testcmp($outfile, $cmpfile) ) {
129 $different = "$outfile is different from $cmpfile";
137 sub testpodplaintext( @ ) {
138 my %opts = (ref $_[0] eq 'HASH') ? %{shift()} : ();
140 my ($testname, $testdir) = ("", "");
141 my ($podfile, $cmpfile) = ("", "");
142 my ($outfile, $errfile) = ("", "");
147 print "1..", scalar @testpods, "\n" unless ($opts{'-xrgen'});
149 for $podfile (@testpods) {
150 ($testname, $_) = fileparse($podfile);
152 $testname =~ s/\.t$//;
153 $cmpfile = $testdir . $testname . '.xr';
154 $outfile = $testdir . $testname . '.OUT';
156 if ($opts{'-xrgen'}) {
157 if ($opts{'-force'} or ! -e $cmpfile) {
158 ## Create the comparison file
159 print "# Creating expected result for \"$testname\"" .
160 " pod2plaintext test ...\n";
161 podinc2plaintext($podfile, $cmpfile);
164 print "# File $cmpfile already exists" .
165 " (use '-force' to regenerate it).\n";
170 my $failmsg = testpodinc2plaintext
176 print "#\tFAILED. ($failmsg)\n";
177 print "not ok ", $failed+$passes, "\n";
182 print "#\tPASSED.\n";
183 print "ok ", $failed+$passes, "\n";