I want to run the Test::Harness magic from a program, but it wasn't designed for that really, and outputs things when it should really be be quiet. No matter: I just turn STDOUT and STDERR into big globs of nothing, then run the private method _run_all_tests() because it is really just runtests() without the report.
However, _run_all_tests() needs to know where to find things that only MakeMaker knows about, so I create an ExtUtils::MM object and peek at things I probably shouldn't know about. It likes to complain too, so I have to do that after STDERR is wiped away (temporarily).
What a little bundle of ugliness, but it's better than fixing the modules.
my( $totals, $failed ) = eval { local @INC = @INC; local *STDOUT; # Shut up Test::Harness! local *STDERR; # Yeah, you too! my $MM = ExtUtils::MM->new(); # and you! unshift @INC, map { File::Spec->rel2abs($_) } @{ $MM }{ qw( INST_LIB INST_ARCHLIB ) }; Test::Harness::_run_all_tests( @test_files ) };
Also, Test::Harness has no knowledge of MakeMaker. Your test programs need to know how to load your libraries. This is done by simply putting blib/lib and blib/arch into @INC.use Test::Harness::Straps;
for my $file (@test_files) {
local *STDERR; # T::H only traps STDOUT.
my %results = Test::Harness::Straps->analyze_file($file);
...do something with the results...
}
Or...use lib qw(blib/lib blib/arch);
use blib; # pro: they're given as absolute paths in case your test chdirs
# con: blib.pm is noisy in older perls