[Chicago-talk] perl tests with overhead

JT Smith jt at plainblack.com
Tue Jul 26 18:30:40 PDT 2005


Thanks, I'll give this a try.

Anybody else got any tips before I get too far?



On Tue, 26 Jul 2005 11:37:44 -0500
  Greg Fast <gdf at speakeasy.net> wrote:
> On Tue, Jul 26, 2005 at 09:57:57AM -0500, JT Smith wrote:
>> The problem comes in that I don't want each test to have to seperately
>> establish a session before running if I can help it. What I'd like to do
>> is create a session and then pass each test a reference to the session.
> 
> I recently hacked together a solution to a similar testing problem,
> using the previously-unknown-to-me Test::Harness::Straps.  This is the
> chunk of Harness that runs the test scripts and analyzes/summarizes
> the output ("1..251", "ok 1", etc).
> 
> I overrode Straps and swapped out the execution of "perl t/$n.t" with
> my own test driver.  This allowed me to factor a large chunk of common
> code out of a test suite (basically: configure a server, fork a
> server, configure a client, run a client, join and cleanup).
> 
> The relevant bits:
> 
>  package MyStraps;
>  use base 'Test::Harness::Straps';
> 
>  sub analyze_file {
>    my $self = shift;
>    my $case_file = shift;
>  
>    # run "<driver> <case_file>"
>    my $cmd = $self->_command_line( $self->driver_cmd ) . " $case_file";
>    open( my $fh, "$cmd |" ) || die $!;
>    return $self->analyze_fh( $case_file, $fh );
>  }
> 
> and:
> 
>  use Test::Harness;
>  $Test::Harness::Strap = MyStraps->new();
>  runtests( @cases ); # t/1.t, t/2.t, ...
> 
> So this lets you do arbitrary work for each test case.  In your
> example, you could easily replace the exec of the test command ("perl
> t/1.t") with a in-process execution that provides a shared session
> (Straps has an analyze() method that takes plain text input), or you
> could write a driver script that loads and stores the session before
> providing it to an exec'd script (to avoid local pollution).
> 
> Normally when you do a "make test", it basically runs runtests().  I
> haven't bothered to hack up Makefile.PL to make it use my straps
> (because this is an integration test suite that requires external
> setup), but it should be possible.
> 
> 
> -- 
> Greg Fast
> gdf at speakeasy.net
> http://cken.chi.groogroo.com/
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk


JT ~ Plain Black
ph: 703-286-2525 ext. 810
fax: 312-264-5382
http://www.plainblack.com

I reject your reality, and substitute my own. ~ Adam Savage


More information about the Chicago-talk mailing list