Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Friday September 03, 2004
04:57 PM

Ugly Test::Harness / MakeMaker kludgery

[ #20720 ]

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 )

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • use Test::Harness::Straps;

    for my $file (@test_files) {
        local *STDERR;  # T::H only traps STDOUT.

        my %results = Test::Harness::Straps->analyze_file($file); something with the results...

    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 lib qw(blib/lib blib/arch);


    use blib;    # pro: they're given as absolu