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 ## remove filenames from error messages to avoid any
38 ## filepath naming differences between OS platforms
39 s/(at line \S+ in file) .*\W(\w+\.[tT])\s*$/$1 \L$2\E/;
40 s/.*\W(\w+\.[tT]) (has \d+ pod syntax error)/\L$1\E $2/;
42 return ($line1 ne $line2);
45 sub testpodcheck( @ ) {
47 my $infile = $args{'-In'} || croak "No input file given!";
48 my $outfile = $args{'-Out'} || croak "No output file given!";
49 my $cmpfile = $args{'-Cmp'} || croak "No compare-result file given!";
52 my $testname = basename $cmpfile, '.t', '.xr';
54 unless (-e $cmpfile) {
55 my $msg = "*** Can't find comparison file $cmpfile for testing $infile";
60 print "# Running podchecker for '$testname'...\n";
61 ## Compare the output against the expected result
63 for ($infile, $outfile, $cmpfile) {
64 $_ = VMS::Filespec::unixify($_) unless ref;
67 podchecker($infile, $outfile);
68 if ( testcmp({'-cmplines' => \&msgcmp}, $outfile, $cmpfile) ) {
69 $different = "$outfile is different from $cmpfile";
77 sub testpodchecker( @ ) {
78 my %opts = (ref $_[0] eq 'HASH') ? %{shift()} : ();
80 my ($testname, $testdir) = ("", "");
81 my ($podfile, $cmpfile) = ("", "");
82 my ($outfile, $errfile) = ("", "");
87 print "1..", scalar @testpods, "\n" unless ($opts{'-xrgen'});
89 for $podfile (@testpods) {
90 ($testname, $_) = fileparse($podfile);
92 $testname =~ s/\.t$//;
93 $cmpfile = $testdir . $testname . '.xr';
94 $outfile = $testdir . $testname . '.OUT';
96 if ($opts{'-xrgen'}) {
97 if ($opts{'-force'} or ! -e $cmpfile) {
98 ## Create the comparison file
99 print "# Creating expected result for \"$testname\"" .
100 " podchecker test ...\n";
101 podchecker($podfile, $cmpfile);
104 print "# File $cmpfile already exists" .
105 " (use '-force' to regenerate it).\n";
110 my $failmsg = testpodcheck
116 print "#\tFAILED. ($failmsg)\n";
117 print "not ok ", $failed+$passes, "\n";
122 print "#\tPASSED.\n";
123 print "ok ", $failed+$passes, "\n";