in reply to use Test; and output

I had pretty much this problem, with a program that sucked some html in, made many transformations, and outputted it, on thousands of files. The problem was, how to verify all the edge cases did what I wanted, all of what I wanted, and nothing but what I wanted. What I wound up doing is basically, a test script that looks like
perl fix_fonts_test.pl C:\thomasdata\thomasprojects\fixhtml\test\fonts +\stripStandard Fixtotext perl fix_fonts_test.pl C:\thomasdata\thomasprojects\fixhtml\test\fonts +\toClassWeiss Fixtoclassweiss perl fix_fonts_test.pl C:\thomasdata\thomasprojects\fixhtml\test\fonts +\toClassRot Fixtoclassrot perl fix_fonts_test.pl C:\thomasdata\thomasprojects\fixhtml\test\fonts +\toClassKlein Fixtoclassklein perl fix_fonts_test.pl C:\thomasdata\thomasprojects\fixhtml\test\fonts +\toClassesKleinNGrau Fixtoclasskleinandgrau
The first arg is a test target directory, the second arg is a "transformer" object. In the test directory, I had various subdirectories, some of which were just placeholders, while others had a "before.html" and "after.html" file inside. The ones with before and after files were identified as test target directories. The script transformed the "before", and compared compared the rest to the "after." Actually, to get this to work I had to put both before and after into a canonical format by trimming whitespace, other little tidbits, but that's the basic idea. Test script:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use File::Find; #custom modules use Modules::Htmlripper::Noreplaceroot::Fixtotext; use Modules::Htmlripper::Gotreplaceroot::Fixtoclassweiss; use Modules::Htmlripper::Gotreplaceroot::Fixtoclassrot; use Modules::Htmlripper::Gotreplaceroot::Fixtoclassklein; use Modules::Htmlripper::Gotnestedreplaceroot::Fixtoclasskleinandgrau; use Modules::Filecontrol qw(get_files); my $test_dir = shift or die "no test directory specified file\n"; opendir (DIR, $test_dir) or die "couldn't open directory: $test_dir"; closedir DIR; my $ripperClass = shift or die "no HTML ripper class specified"; my @test_dirs = Filecontrol::get_test_dirs($test_dir); my $ripper = $ripperClass->new(); #keys are directory names. for ( @test_dirs ) { print "Testing $ripperClass against directory $_: \n"; $ripper->test_dir($_); my $result = $ripper->test(); if ($result) { print "ok\n"; } else { print "not ok\n"; } }
Test dir grabber:
sub get_test_dirs { my $dir = shift or die "no directory specified."; opendir (DIR, $dir) or die "couldn't open directory: $dir"; my @directories_to_search = ("$dir"); my %dirs = (); find( sub { if (-d $File::Find::name) { # it's a dir my $current_dir = $File::Find::name; if ( (-f "$current_dir" . '/before.html') && (-f "$cur +rent_dir" . '/after.html') ) { #before and after files exist $dirs{$current_dir} = 1; } #end check if file } # end check if directory }, @directories_to_search ); my @dirs = keys %dirs; return @dirs; }
Maybe you can adopt this to your situation. Hope this helps!