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 require Pod::PlainText;
28 @ISA = qw( Pod::PlainText );
29 require VMS::Filespec if $^O eq 'VMS';
32 ## Hardcode settings for TERMCAP and COLUMNS so we can try to get
33 ## reproducible results between environments
34 @ENV{qw(TERMCAP COLUMNS)} = ('co=76:do=^J', 76);
36 sub catfile(@) { File::Spec->catfile(@_); }
38 my $INSTDIR = abs_path(dirname $0);
39 $INSTDIR = VMS::Filespec::unixpath($INSTDIR) if $^O eq 'VMS';
40 $INSTDIR =~ s#/$## if $^O eq 'VMS';
41 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 'pod');
42 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 't');
43 my @PODINCDIRS = ( catfile($INSTDIR, 'lib', 'Pod'),
44 catfile($INSTDIR, 'scripts'),
45 catfile($INSTDIR, 'pod'),
46 catfile($INSTDIR, 't', 'pod')
49 ## Find the path to the file to =include
54 ## See if its already found w/out any "searching;
55 return $incname if (-r $incname);
57 ## Need to search for it. Look in the following directories ...
58 ## 1. the directory containing this pod file
59 my $thispoddir = dirname $self->input_file;
60 ## 2. the parent directory of the above
61 my $parentdir = dirname $thispoddir;
62 my @podincdirs = ($thispoddir, $parentdir, @PODINCDIRS);
65 my $incfile = catfile($_, $incname);
66 return $incfile if (-r $incfile);
68 warn("*** Can't find =include file $incname in @podincdirs\n");
74 my ($cmd, $text, $line_num, $pod_para) = @_;
75 $cmd = '' unless (defined $cmd);
76 local $_ = $text || '';
77 my $out_fh = $self->output_handle;
79 ## Defer to the superclass for everything except '=include'
80 return $self->SUPER::command(@_) unless ($cmd eq "include");
82 ## We have an '=include' command
83 my $incdebug = 1; ## debugging
86 warn("*** No filename given for '=include'\n");
89 my $incfile = $self->findinclude(shift @incargs) or return;
90 my $incbase = basename $incfile;
91 print $out_fh "###### begin =include $incbase #####\n" if ($incdebug);
92 $self->parse_from_file( {-cutting => 1}, $incfile );
93 print $out_fh "###### end =include $incbase #####\n" if ($incdebug);
97 $_[0]->{_INFILE} = VMS::Filespec::unixify($_[0]->{_INFILE}) if $^O eq 'VMS';
100 sub podinc2plaintext( $ $ ) {
101 my ($infile, $outfile) = @_;
103 my $text_parser = $MYPKG->new;
104 $text_parser->parse_from_file($infile, $outfile);
107 sub testpodinc2plaintext( @ ) {
109 my $infile = $args{'-In'} || croak "No input file given!";
110 my $outfile = $args{'-Out'} || croak "No output file given!";
111 my $cmpfile = $args{'-Cmp'} || croak "No compare-result file given!";
114 my $testname = basename $cmpfile, '.t', '.xr';
116 unless (-e $cmpfile) {
117 my $msg = "*** Can't find comparison file $cmpfile for testing $infile";
122 print "# Running testpodinc2plaintext for '$testname'...\n";
123 ## Compare the output against the expected result
124 podinc2plaintext($infile, $outfile);
125 if ( testcmp($outfile, $cmpfile) ) {
126 $different = "$outfile is different from $cmpfile";
134 sub testpodplaintext( @ ) {
135 my %opts = (ref $_[0] eq 'HASH') ? %{shift()} : ();
137 my ($testname, $testdir) = ("", "");
138 my ($podfile, $cmpfile) = ("", "");
139 my ($outfile, $errfile) = ("", "");
144 print "1..", scalar @testpods, "\n" unless ($opts{'-xrgen'});
146 for $podfile (@testpods) {
147 ($testname, $_) = fileparse($podfile);
149 $testname =~ s/\.t$//;
150 $cmpfile = $testdir . $testname . '.xr';
151 $outfile = $testdir . $testname . '.OUT';
153 if ($opts{'-xrgen'}) {
154 if ($opts{'-force'} or ! -e $cmpfile) {
155 ## Create the comparison file
156 print "# Creating expected result for \"$testname\"" .
157 " pod2plaintext test ...\n";
158 podinc2plaintext($podfile, $cmpfile);
161 print "# File $cmpfile already exists" .
162 " (use '-force' to regenerate it).\n";
167 my $failmsg = testpodinc2plaintext
173 print "#\tFAILED. ($failmsg)\n";
174 print "not ok ", $failed+$passes, "\n";
179 print "#\tPASSED.\n";
180 print "ok ", $failed+$passes, "\n";