You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tyler MacDonald <ty...@yi.org> on 2005/10/31 03:57:20 UTC

Apache::Test and Devel::Cover

I'm trying to get code coverage metrics of an apache2 module I'm developing,
using Devel::Cover. I've figured out a way to do it, but it's a bit hacky
:-)

Devel::Cover instructs you to run "make test" like so:

HARNESS_PERL_SWITCHES=-MDevel::Cover make test

to get coverage analysis. What I've done to make the apache server use this
is:

1) Add "PerlPassEnv HARNESS_PERL_SWITCHES" to my extra.last.conf.in

2) Add the following block of code to my modperl_extra.pl:

if(
    $ENV{HARNESS_PERL_SWITCHES} &&
    $ENV{HARNESS_PERL_SWITCHES} =~ m{Devel::Cover}
) {
    eval "use Devel::Cover;";
}

Is this the cleanest way to accomplish this? Ideally I would have liked
something that could be done with any mod_perl module without adding code to
the test suite itself... any ideas?

	Thanks,
		Tyler


Re: Apache::Test and Devel::Cover

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Tyler MacDonald wrote:
> Geoffrey Young <ge...@modperlcookbook.org> wrote:
> 
>>>Disregard, I just searched the archives and apparently just before I
>>>subscribed to the list Phillippe announced the 'testcover' parameter...
>>>which is documented in Apache::TestMB, but not yet in Apache::TestMM :-/
>>
>>but that's only half the story - you still need the stuff you did.  see the
>>generated Makefile for what testcover does.
> 
> 
> 	Yup, I played around with it, thought it was working for a second,
> then found that it didn't, got angry, took a breather, came back, and added
> -MDevel::Cover to my PerlSwitches. Then everything was happy. :-)

um, the Makefile should do that for you already

    testcover :
      -@cover -delete
      -HARNESS_PERL_SWITCHES=-MDevel::Cover=+inc,/home/geoff/.apache-test \
      APACHE_TEST_EXTRA_ARGS=-one-process $(MAKE) test
      -@cover

> 	Do you think it would be a good idea to have "make testcover" add
> -MDevel::Cover into the httpd.conf for us? 

yeah, it's about time we do that.  try this patch against current svn - it
seems to work for me.

--Geoff

Re: Apache::Test and Devel::Cover

Posted by Tyler MacDonald <ty...@yi.org>.
Geoffrey Young <ge...@modperlcookbook.org> wrote:
> > Disregard, I just searched the archives and apparently just before I
> > subscribed to the list Phillippe announced the 'testcover' parameter...
> > which is documented in Apache::TestMB, but not yet in Apache::TestMM :-/
> but that's only half the story - you still need the stuff you did.  see the
> generated Makefile for what testcover does.

	Yup, I played around with it, thought it was working for a second,
then found that it didn't, got angry, took a breather, came back, and added
-MDevel::Cover to my PerlSwitches. Then everything was happy. :-)

	Do you think it would be a good idea to have "make testcover" add
-MDevel::Cover into the httpd.conf for us? I just started playing with
Apache::Test tonight so I'm not too sure how easy/advisable this would be...

	Cheers,
		Tyler


Re: Apache::Test and Devel::Cover

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Tyler MacDonald wrote:
> Disregard, I just searched the archives and apparently just before I
> subscribed to the list Phillippe announced the 'testcover' parameter...
> which is documented in Apache::TestMB, but not yet in Apache::TestMM :-/

but that's only half the story - you still need the stuff you did.  see the
generated Makefile for what testcover does.

--Geoff

Re: Apache::Test and Devel::Cover

Posted by Tyler MacDonald <ty...@yi.org>.
Disregard, I just searched the archives and apparently just before I
subscribed to the list Phillippe announced the 'testcover' parameter...
which is documented in Apache::TestMB, but not yet in Apache::TestMM :-/

	- Tyler


Tyler MacDonald <ty...@yi.org> wrote:
> I'm trying to get code coverage metrics of an apache2 module I'm developing,
> using Devel::Cover. I've figured out a way to do it, but it's a bit hacky
> :-)
> 
> Devel::Cover instructs you to run "make test" like so:
> 
> HARNESS_PERL_SWITCHES=-MDevel::Cover make test
> 
> to get coverage analysis. What I've done to make the apache server use this
> is:
> 
> 1) Add "PerlPassEnv HARNESS_PERL_SWITCHES" to my extra.last.conf.in
> 
> 2) Add the following block of code to my modperl_extra.pl:
> 
> if(
>     $ENV{HARNESS_PERL_SWITCHES} &&
>     $ENV{HARNESS_PERL_SWITCHES} =~ m{Devel::Cover}
> ) {
>     eval "use Devel::Cover;";
> }
> 
> Is this the cleanest way to accomplish this? Ideally I would have liked
> something that could be done with any mod_perl module without adding code to
> the test suite itself... any ideas?
> 
> 	Thanks,
> 		Tyler
> 

Re: Apache::Test and Devel::Cover

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Tyler MacDonald wrote:
> I'm trying to get code coverage metrics of an apache2 module I'm developing,
> using Devel::Cover. I've figured out a way to do it, but it's a bit hacky
> :-)
> 
> Devel::Cover instructs you to run "make test" like so:
> 
> HARNESS_PERL_SWITCHES=-MDevel::Cover make test
> 
> to get coverage analysis. What I've done to make the apache server use this
> is:
> 
> 1) Add "PerlPassEnv HARNESS_PERL_SWITCHES" to my extra.last.conf.in
> 
> 2) Add the following block of code to my modperl_extra.pl:
> 
> if(
>     $ENV{HARNESS_PERL_SWITCHES} &&
>     $ENV{HARNESS_PERL_SWITCHES} =~ m{Devel::Cover}
> ) {
>     eval "use Devel::Cover;";
> }
> 
> Is this the cleanest way to accomplish this? 

it's pretty much the only way at this point.  see

  http://search.cpan.org/src/GEOFF/Apache-SSLLookup-2.00_04/

for pretty much those exact steps :)

I keep meaning to document this.  doc patches much appreciated.

> Ideally I would have liked
> something that could be done with any mod_perl module without adding code to
> the test suite itself... 

it can't really be done without making those changes.  at least not at the
moment.  I guess we could have TestConfigPerl put in the appropriate foo in
the generated httpd.conf though...

--Geoff