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);
16 use vars qw(@ISA @EXPORT $MYPKG);
24 @EXPORT = qw(&testpodchecker);
25 $MYPKG = eval { (caller)[0] };
29 return /(\w[.\w]*)\s*$/ ? $1 : $_;
33 my ($line1, $line2) = @_;
34 return $line1 ne $line2;
37 sub testpodcheck( @ ) {
39 my $infile = $args{'-In'} || croak "No input file given!";
40 my $outfile = $args{'-Out'} || croak "No output file given!";
41 my $cmpfile = $args{'-Cmp'} || croak "No compare-result file given!";
44 my $testname = basename $cmpfile, '.t', '.xr';
46 unless (-e $cmpfile) {
47 my $msg = "*** Can't find comparison file $cmpfile for testing $infile";
52 print "# Running podchecker for '$testname'...\n";
53 ## Compare the output against the expected result
54 podchecker($infile, $outfile);
55 if ( testcmp({'-cmplines' => \&msgcmp}, $outfile, $cmpfile) ) {
56 $different = "$outfile is different from $cmpfile";
64 sub testpodchecker( @ ) {
65 my %opts = (ref $_[0] eq 'HASH') ? %{shift()} : ();
67 my ($testname, $testdir) = ("", "");
68 my ($podfile, $cmpfile) = ("", "");
69 my ($outfile, $errfile) = ("", "");
74 print "1..", scalar @testpods, "\n" unless ($opts{'-xrgen'});
76 for $podfile (@testpods) {
77 ($testname, $_) = fileparse($podfile);
79 $testname =~ s/\.t$//;
80 $cmpfile = $testdir . $testname . '.xr';
81 $outfile = $testdir . $testname . '.OUT';
83 if ($opts{'-xrgen'}) {
84 if ($opts{'-force'} or ! -e $cmpfile) {
85 ## Create the comparison file
86 print "# Creating expected result for \"$testname\"" .
87 " podchecker test ...\n";
88 podchecker($podfile, $cmpfile);
91 print "# File $cmpfile already exists" .
92 " (use '-force' to regenerate it).\n";
97 my $failmsg = testpodcheck
103 print "#\tFAILED. ($failmsg)\n";
104 print "not ok ", $failed+$passes, "\n";
109 print "#\tPASSED.\n";
110 print "ok ", $failed+$passes, "\n";