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);
17 use vars qw(@ISA @EXPORT $MYPKG);
23 #use Cwd qw(abs_path);
25 @ISA = qw(Pod::PlainText);
26 @EXPORT = qw(&testpodplaintext);
27 $MYPKG = eval { (caller)[0] };
29 ## Hardcode settings for TERMCAP and COLUMNS so we can try to get
30 ## reproducible results between environments
31 @ENV{qw(TERMCAP COLUMNS)} = ('co=72:do=^J', 72);
33 sub catfile(@) { File::Spec->catfile(@_); }
35 my $INSTDIR = abs_path(dirname $0);
36 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 'xtra');
37 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 'pod');
38 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 't');
39 my @PODINCDIRS = ( catfile($INSTDIR, 'lib', 'Pod'),
40 catfile($INSTDIR, 'scripts'),
41 catfile($INSTDIR, 't', 'pod'),
42 catfile($INSTDIR, 't', 'pod', 'xtra')
45 ## Find the path to the file to =include
50 ## See if its already found w/out any "searching;
51 return $incname if (-r $incname);
53 ## Need to search for it. Look in the following directories ...
54 ## 1. the directory containing this pod file
55 my $thispoddir = dirname $self->input_file;
56 ## 2. the parent directory of the above
57 my $parentdir = dirname $thispoddir;
58 my @podincdirs = ($thispoddir, $parentdir, @PODINCDIRS);
61 my $incfile = catfile($_, $incname);
62 return $incfile if (-r $incfile);
64 warn("*** Can't find =include file $incname in @podincdirs\n");
70 my ($cmd, $text, $line_num, $pod_para) = @_;
71 $cmd = '' unless (defined $cmd);
72 local $_ = $text || '';
73 my $out_fh = $self->output_handle;
75 ## Defer to the superclass for everything except '=include'
76 return $self->SUPER::command(@_) unless ($cmd eq "include");
78 ## We have an '=include' command
79 my $incdebug = 1; ## debugging
82 warn("*** No filename given for '=include'\n");
85 my $incfile = $self->findinclude(shift @incargs) or return;
86 my $incbase = basename $incfile;
87 print $out_fh "###### begin =include $incbase #####\n" if ($incdebug);
88 $self->parse_from_file( {-cutting => 1}, $incfile );
89 print $out_fh "###### end =include $incbase #####\n" if ($incdebug);
92 sub podinc2plaintext( $ $ ) {
93 my ($infile, $outfile) = @_;
95 my $text_parser = $MYPKG->new;
96 $text_parser->parse_from_file($infile, $outfile);
99 sub testpodinc2plaintext( @ ) {
101 my $infile = $args{'-In'} || croak "No input file given!";
102 my $outfile = $args{'-Out'} || croak "No output file given!";
103 my $cmpfile = $args{'-Cmp'} || croak "No compare-result file given!";
106 my $testname = basename $cmpfile, '.t', '.xr';
108 unless (-e $cmpfile) {
109 my $msg = "*** Can't find comparison file $cmpfile for testing $infile";
114 print "+ Running testpodinc2plaintext for '$testname'...\n";
115 ## Compare the output against the expected result
116 podinc2plaintext($infile, $outfile);
117 if ( testcmp($outfile, $cmpfile) ) {
118 $different = "$outfile is different from $cmpfile";
126 sub testpodplaintext( @ ) {
127 my %opts = (ref $_[0] eq 'HASH') ? %{shift()} : ();
129 my ($testname, $testdir) = ("", "");
130 my ($podfile, $cmpfile) = ("", "");
131 my ($outfile, $errfile) = ("", "");
136 print "1..", scalar @testpods, "\n" unless ($opts{'-xrgen'});
138 for $podfile (@testpods) {
139 ($testname, $_) = fileparse($podfile);
141 $testname =~ s/\.t$//;
142 $cmpfile = $testdir . $testname . '.xr';
143 $outfile = $testdir . $testname . '.OUT';
145 if ($opts{'-xrgen'}) {
146 if ($opts{'-force'} or ! -e $cmpfile) {
147 ## Create the comparison file
148 print "+ Creating expected result for \"$testname\"" .
149 " pod2plaintext test ...\n";
150 podinc2plaintext($podfile, $cmpfile);
153 print "+ File $cmpfile already exists" .
154 " (use '-force' to regenerate it).\n";
159 my $failmsg = testpodinc2plaintext
165 print "+\tFAILED. ($failmsg)\n";
166 print "not ok ", $failed+$passes, "\n";
171 print "+\tPASSED.\n";
172 print "ok ", $failed+$passes, "\n";