Remove code specific to MacOS Classic from core tests
[p5sagit/p5-mst-13.2.git] / t / pod / testp2pt.pl
CommitLineData
360aca43 1package TestPodIncPlainText;
2
3BEGIN {
4 use File::Basename;
5 use File::Spec;
e9fdc7d2 6 use Cwd qw(abs_path);
360aca43 7 push @INC, '..';
e9fdc7d2 8 my $THISDIR = abs_path(dirname $0);
360aca43 9 unshift @INC, $THISDIR;
10 require "testcmp.pl";
11 import TestCompare;
12 my $PARENTDIR = dirname $THISDIR;
13 push @INC, map { File::Spec->catfile($_, 'lib') } ($PARENTDIR, $THISDIR);
14}
15
360aca43 16#use strict;
17#use diagnostics;
18use Carp;
19use Exporter;
20#use File::Compare;
e9fdc7d2 21#use Cwd qw(abs_path);
360aca43 22
664bb207 23use vars qw($MYPKG @EXPORT @ISA);
360aca43 24$MYPKG = eval { (caller)[0] };
664bb207 25@EXPORT = qw(&testpodplaintext);
26BEGIN {
9c6ed6d7 27 require Pod::PlainText;
28 @ISA = qw( Pod::PlainText );
f0963acb 29 require VMS::Filespec if $^O eq 'VMS';
664bb207 30}
360aca43 31
32## Hardcode settings for TERMCAP and COLUMNS so we can try to get
33## reproducible results between environments
664bb207 34@ENV{qw(TERMCAP COLUMNS)} = ('co=76:do=^J', 76);
360aca43 35
36sub catfile(@) { File::Spec->catfile(@_); }
37
e9fdc7d2 38my $INSTDIR = abs_path(dirname $0);
9c6ed6d7 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');
e9fdc7d2 43my @PODINCDIRS = ( catfile($INSTDIR, 'lib', 'Pod'),
828c4421 44 catfile($INSTDIR, 'scripts'),
27f805f4 45 catfile($INSTDIR, 'pod'),
828c4421 46 catfile($INSTDIR, 't', 'pod')
e9fdc7d2 47 );
48
360aca43 49## Find the path to the file to =include
50sub findinclude {
51 my $self = shift;
52 my $incname = shift;
53
54 ## See if its already found w/out any "searching;
55 return $incname if (-r $incname);
56
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
e9fdc7d2 61 my $parentdir = dirname $thispoddir;
62 my @podincdirs = ($thispoddir, $parentdir, @PODINCDIRS);
360aca43 63
64 for (@podincdirs) {
65 my $incfile = catfile($_, $incname);
66 return $incfile if (-r $incfile);
67 }
68 warn("*** Can't find =include file $incname in @podincdirs\n");
69 return "";
70}
71
72sub command {
73 my $self = shift;
74 my ($cmd, $text, $line_num, $pod_para) = @_;
75 $cmd = '' unless (defined $cmd);
76 local $_ = $text || '';
77 my $out_fh = $self->output_handle;
78
79 ## Defer to the superclass for everything except '=include'
80 return $self->SUPER::command(@_) unless ($cmd eq "include");
81
82 ## We have an '=include' command
83 my $incdebug = 1; ## debugging
84 my @incargs = split;
85 if (@incargs == 0) {
86 warn("*** No filename given for '=include'\n");
87 return;
88 }
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);
94}
95
828c4421 96sub begin_input {
97 $_[0]->{_INFILE} = VMS::Filespec::unixify($_[0]->{_INFILE}) if $^O eq 'VMS';
98}
99
360aca43 100sub podinc2plaintext( $ $ ) {
101 my ($infile, $outfile) = @_;
102 local $_;
9c6ed6d7 103 my $text_parser = $MYPKG->new;
360aca43 104 $text_parser->parse_from_file($infile, $outfile);
105}
106
107sub testpodinc2plaintext( @ ) {
108 my %args = @_;
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!";
112
113 my $different = '';
114 my $testname = basename $cmpfile, '.t', '.xr';
115
116 unless (-e $cmpfile) {
117 my $msg = "*** Can't find comparison file $cmpfile for testing $infile";
118 warn "$msg\n";
119 return $msg;
120 }
121
27f805f4 122 print "# Running testpodinc2plaintext for '$testname'...\n";
360aca43 123 ## Compare the output against the expected result
124 podinc2plaintext($infile, $outfile);
125 if ( testcmp($outfile, $cmpfile) ) {
126 $different = "$outfile is different from $cmpfile";
127 }
128 else {
129 unlink($outfile);
130 }
131 return $different;
132}
133
134sub testpodplaintext( @ ) {
135 my %opts = (ref $_[0] eq 'HASH') ? %{shift()} : ();
136 my @testpods = @_;
137 my ($testname, $testdir) = ("", "");
138 my ($podfile, $cmpfile) = ("", "");
139 my ($outfile, $errfile) = ("", "");
140 my $passes = 0;
141 my $failed = 0;
142 local $_;
143
144 print "1..", scalar @testpods, "\n" unless ($opts{'-xrgen'});
145
146 for $podfile (@testpods) {
147 ($testname, $_) = fileparse($podfile);
148 $testdir ||= $_;
9c6ed6d7 149 $testname =~ s/\.t$//;
360aca43 150 $cmpfile = $testdir . $testname . '.xr';
151 $outfile = $testdir . $testname . '.OUT';
152
153 if ($opts{'-xrgen'}) {
154 if ($opts{'-force'} or ! -e $cmpfile) {
155 ## Create the comparison file
27f805f4 156 print "# Creating expected result for \"$testname\"" .
360aca43 157 " pod2plaintext test ...\n";
158 podinc2plaintext($podfile, $cmpfile);
159 }
160 else {
27f805f4 161 print "# File $cmpfile already exists" .
360aca43 162 " (use '-force' to regenerate it).\n";
163 }
164 next;
165 }
166
167 my $failmsg = testpodinc2plaintext
168 -In => $podfile,
169 -Out => $outfile,
170 -Cmp => $cmpfile;
171 if ($failmsg) {
172 ++$failed;
27f805f4 173 print "#\tFAILED. ($failmsg)\n";
360aca43 174 print "not ok ", $failed+$passes, "\n";
175 }
176 else {
177 ++$passes;
178 unlink($outfile);
27f805f4 179 print "#\tPASSED.\n";
360aca43 180 print "ok ", $failed+$passes, "\n";
181 }
182 }
183 return $passes;
184}
185
1861;