1 package TestPodChecker;
7 my $THISDIR = dirname $0;
8 unshift @INC, $THISDIR;
11 my $PARENTDIR = dirname $THISDIR;
12 push @INC, map { File::Spec->catfile($_, 'lib') } ($PARENTDIR, $THISDIR);
13 require VMS::Filespec if $^O eq 'VMS';
17 use vars qw(@ISA @EXPORT $MYPKG);
25 @EXPORT = qw(&testpodchecker);
26 $MYPKG = eval { (caller)[0] };
30 return /(\w[.\w]*)\s*$/ ? $1 : $_;
34 ## filter out platform-dependent aspects of error messages
35 my ($line1, $line2) = @_;
36 for ($line1, $line2) {
37 if ( /^#*\s*(\S.*?)\s+(?:has \d+\s*)?pod syntax (?:error|OK)/ ) {
39 s/^#*\s*// if ($^O eq 'MacOS');
40 s/^\s*\Q$fname\E/stripname($fname)/e;
42 elsif ( /^#*\s*\*+\s*(?:ERROR|Unterminated)/ ) {
43 s/^#*\s*// if ($^O eq 'MacOS');
44 s/of file\s+(\S.*?)\s*$/"of file ".stripname($1)/e;
45 s/at\s+(\S.*?)\s+line/"at ".stripname($1)." line"/e;
48 return $line1 ne $line2;
51 sub testpodcheck( @ ) {
53 my $infile = $args{'-In'} || croak "No input file given!";
54 my $outfile = $args{'-Out'} || croak "No output file given!";
55 my $cmpfile = $args{'-Cmp'} || croak "No compare-result file given!";
58 my $testname = basename $cmpfile, '.t', '.xr';
60 unless (-e $cmpfile) {
61 my $msg = "*** Can't find comparison file $cmpfile for testing $infile";
66 print "# Running podchecker for '$testname'...\n";
67 ## Compare the output against the expected result
69 for ($infile, $outfile, $cmpfile) {
70 $_ = VMS::Filespec::unixify($_) unless ref;
73 podchecker($infile, $outfile);
74 if ( testcmp({'-cmplines' => \&msgcmp}, $outfile, $cmpfile) ) {
75 $different = "$outfile is different from $cmpfile";
83 sub testpodchecker( @ ) {
84 my %opts = (ref $_[0] eq 'HASH') ? %{shift()} : ();
86 my ($testname, $testdir) = ("", "");
87 my ($podfile, $cmpfile) = ("", "");
88 my ($outfile, $errfile) = ("", "");
93 print "1..", scalar @testpods, "\n" unless ($opts{'-xrgen'});
95 for $podfile (@testpods) {
96 ($testname, $_) = fileparse($podfile);
98 $testname =~ s/\.t$//;
99 $cmpfile = $testdir . $testname . '.xr';
100 $outfile = $testdir . $testname . '.OUT';
102 if ($opts{'-xrgen'}) {
103 if ($opts{'-force'} or ! -e $cmpfile) {
104 ## Create the comparison file
105 print "# Creating expected result for \"$testname\"" .
106 " podchecker test ...\n";
107 podchecker($podfile, $cmpfile);
110 print "# File $cmpfile already exists" .
111 " (use '-force' to regenerate it).\n";
116 my $failmsg = testpodcheck
122 print "#\tFAILED. ($failmsg)\n";
123 print "not ok ", $failed+$passes, "\n";
128 print "#\tPASSED.\n";
129 print "ok ", $failed+$passes, "\n";