Perl test-suite for validating POD

I've been hacking on my Perl search engine module, which I will finish off soon, and I started hacking up a test suite. This is mainly to test the stuff which handles character encodings, because it has to work on Perl 5.6 and 5.8, which is a bit of a nightmare to do. It means lots of fiddling and testing things on two different machines at every juncture.

While I was doing this I noticed the existence of podchecker, which is a little command-line Perl program which wraps the Pod::Checker module. It validates the documentation in Perl modules, warning of syntax errors (unknown commands and such). So I added a little test program called 99pod.t to my test suite to check the POD documentation in all my .pm files (it assumes they all live under lib, which seems to be the usual arrangement).

Anyway, this is one test program which might usefully be plugged in to many Perl modules, so the here's the code. It's public domain; do what you want with it. It's fairly simple. The only tricky bit is that you have to tell Pod::Checker to write its error messages to a temporary file and only dump that to STDERR if there were actually any errors. That's to avoid messages about your syntax being OK. I prefer the normal Unix convention of “no output means no problem”.

# Validate the POD documentation in all Perl modules (*.pm) under the 'lib'
# directory.  Prints a warning if no documentation was found (because that
# probably means you should write some).

use strict;
use warnings;
use Test;
use File::Find;
use Pod::Checker;
use File::Temp qw( tempfile );
use IO::File;


# Each test is for a particular '.pm' file, so we need to find how many
# there are before we plan the tests.
my @pm;
find({ wanted => \&wanted, no_chdir => 1 }, 'lib');

sub wanted
{
   return unless -f;
   return unless /\.pm$/;
   push @pm, $_;
}

plan tests => scalar @pm;


foreach (@pm) {
   # Warnings are sent to a temporary file.
   my ($log_file, $log_filename) = tempfile();

   my $s = podchecker($_, $log_file, '-warnings' => 2);
   close $log_file;

   warn "\n$_: no documentation.\n" if $s < 0;
   if ($s > 0) {
      $log_file = IO::File->new($log_filename, 'r')
         or die "$0: error rereading log file '$log_filename': $!\n";
      my $log = do { local $/; <$log_file> };
      warn "\n$log\n";
   }

   ok($s <= 0);
   unlink $log_filename;
}

# vim:ft=perl ts=3 sw=3 expandtab:

< Serendipitous Washing Machine | Moved house, John & Ali's wedding >

Miniblog

(nuggets of inanity)

Tuesday Apr 24th 2007, 16:54 »
Just took the annual web design survey that AListApart do. I don't realy consider myself to be a web designer, but I have been doing a lot of HTML and CSS lately.
Monday Apr 23rd 2007, 18:23 »
Strange, there appears to be a bare-knuckle boxing match going on in the field outside my flat. Wish they wouldn't make so much noise about it.
Thursday Mar 1st 2007, 18:47 »
“In its written form, Hebrew has no vowels, making it the ideal language for texting.”
—Said in jest on some Radio 4 programme just now.

Archive: 2007 · 2006 · 2005 · 2004
Feed