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 if ($^O eq 'VMS') { # clean up directory spec
46 $INSTDIR = VMS::Filespec::unixpath($INSTDIR);
48 $INSTDIR =~ s#/000000/#/#;
50 # cut 't/pod' from path (cut 't:pod:' on Mac OS)
51 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 'pod');
52 $INSTDIR = (dirname $INSTDIR) if (basename($INSTDIR) eq 't');
54 my @PODINCDIRS = ( catfile($INSTDIR, 'lib', 'Pod'),
55 catfile($INSTDIR, 'scripts'),
56 catfile($INSTDIR, 'pod'),
57 catfile($INSTDIR, 't', 'pod')
59 print "PODINCDIRS = ",join(', ',@PODINCDIRS),"\n";
61 ## Find the path to the file to =include
66 ## See if its already found w/out any "searching;
67 return $incname if (-r $incname);
69 ## Need to search for it. Look in the following directories ...
70 ## 1. the directory containing this pod file
71 my $thispoddir = dirname $self->input_file;
72 ## 2. the parent directory of the above
73 my $parentdir = dirname $thispoddir;
74 my @podincdirs = ($thispoddir, $parentdir, @PODINCDIRS);
77 my $incfile = catfile($_, $incname);
78 return $incfile if (-r $incfile);
80 warn("*** Can't find =include file $incname in @podincdirs\n");
86 my ($cmd, $text, $line_num, $pod_para) = @_;
87 $cmd = '' unless (defined $cmd);
88 local $_ = $text || '';
89 my $out_fh = $self->output_handle;
91 ## Defer to the superclass for everything except '=include'
92 return $self->SUPER::command(@_) unless ($cmd eq "include");
94 ## We have an '=include' command
95 my $incdebug = 1; ## debugging
98 warn("*** No filename given for '=include'\n");
101 my $incfile = $self->findinclude(shift @incargs) or return;
102 my $incbase = basename $incfile;
103 print $out_fh "###### begin =include $incbase #####\n" if ($incdebug);
104 $self->parse_from_file( {-cutting => 1}, $incfile );
105 print $out_fh "###### end =include $incbase #####\n" if ($incdebug);
109 $_[0]->{_INFILE} = VMS::Filespec::unixify($_[0]->{_INFILE}) if $^O eq 'VMS';
112 sub podinc2plaintext( $ $ ) {
113 my ($infile, $outfile) = @_;
115 my $text_parser = $MYPKG->new(quotes => "`'");
116 $text_parser->parse_from_file($infile, $outfile);
119 sub testpodinc2plaintext( @ ) {
121 my $infile = $args{'-In'} || croak "No input file given!";
122 my $outfile = $args{'-Out'} || croak "No output file given!";
123 my $cmpfile = $args{'-Cmp'} || croak "No compare-result file given!";
126 my $testname = basename $cmpfile, '.t', '.xr';
128 unless (-e $cmpfile) {
129 my $msg = "*** Can't find comparison file $cmpfile for testing $infile";
134 print "# Running testpodinc2plaintext for '$testname'...\n";
135 ## Compare the output against the expected result
136 podinc2plaintext($infile, $outfile);
137 if ( testcmp($outfile, $cmpfile) ) {
138 $different = "$outfile is different from $cmpfile";
146 sub testpodplaintext( @ ) {
147 my %opts = (ref $_[0] eq 'HASH') ? %{shift()} : ();
149 my ($testname, $testdir) = ("", "");
150 my ($podfile, $cmpfile) = ("", "");
151 my ($outfile, $errfile) = ("", "");
156 print "1..", scalar @testpods, "\n" unless ($opts{'-xrgen'});
158 for $podfile (@testpods) {
159 ($testname, $_) = fileparse($podfile);
161 $testname =~ s/\..*$//;
162 $cmpfile = $testdir . $testname . '.xr';
163 $outfile = $testdir . $testname . '.OUT';
165 if ($opts{'-xrgen'}) {
166 if ($opts{'-force'} or ! -e $cmpfile) {
167 ## Create the comparison file
168 print "# Creating expected result for \"$testname\"" .
169 " pod2plaintext test ...\n";
170 podinc2plaintext($podfile, $cmpfile);
173 print "# File $cmpfile already exists" .
174 " (use '-force' to regenerate it).\n";
179 my $failmsg = testpodinc2plaintext
185 print "#\tFAILED. ($failmsg)\n";
186 print "not ok ", $failed+$passes, "\n";
191 print "#\tPASSED.\n";
192 print "ok ", $failed+$passes, "\n";