More helpful module tests

petdance on 2003-06-19T14:58:05

I hate releasing things where I've accidentally left XXXed code to look at later. So, I made a t/98.rules.t that fails if I've forgotten any XXXes in my files:

use Test::More tests => 2; use File::Spec; use strict;

my $file = File::Spec->catfile( qw( lib WWW ), "Mechanize.pm" ); source_file_ok( $file );

$file = File::Spec->catfile( qw( lib WWW Mechanize ), "Examples.pod" ); source_file_ok( $file );

sub source_file_ok { my $file = shift;

open( my $fh, "<", $file ) or die "Can't open $file: $!"; my @lines = <$fh>; close $fh;

my $n = 0; for ( @lines ) { ++$n; s/^/$file ($n): /; }

my @x = grep /XXX/, @lines;

if ( !is( scalar @x, 0, "Looking for XXXes" ) ) { diag( $_ ) for @x; } }