Hi all,

Test::Class can speed up your your tests by ensuring that perl and
related modules are loaded only once.  I was thinking about how this
could be done with normal .t files and a colleague mentioned some stuff
that Apache::Registry does and I thought it would be interesting to see
if I could incorporate its methodology.

I've posted the outline of the idea and the code at
http://www.perlmonks.org/?node_id=652605.  It would take some work to
get this production ready, but basically it does the following:

  test = ''
  foreach .t file:
     code = slurp(file)
     create a unique package name
     test .= <<"END_CODE";
     package $package

     sub handler {
$code
     }
END_CODE
  end foerach

  eval test
  BAILOUT($@) if $@;

  foreach package in packages
      package->handler
  end

Just as with mod_perl, there are caveats on how you can write your
tests:

 * no __DATA__ or __END__ blocks.
 * Don't rely on implicit behavior of cleanup in END blocks.
 * I've had 'use Config' and IPC:: code fail, but I don't know why.

Right now it's just a toy, but my initial work shows that I can gain a 
speedup on test suites if they can be run with this.  A conceptually
similar idea reduced test time to 1/3rd of its original time.

Cheers,
Ovid

--
Buy the book  - http://www.oreilly.com/catalog/perlhks/
Perl and CGI  - http://users.easystreet.com/ovid/cgi_course/
Personal blog - http://publius-ovidius.livejournal.com/
Tech blog     - http://use.perl.org/~Ovid/journal/

Reply via email to