You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Geoffrey Young <ge...@modperlcookbook.org> on 2004/08/02 17:47:17 UTC

[PATCH] new need functions

hi all

ok, attached is a patch that implements the new need variants and alters the
old have variants.  basically, all I did was a global rename of have to
need, then implement the have routines in terms of need with the AutoLoader.
 I thought this made a bit more sense than redefining all of those
subroutines again when the only difference was simply not populating
@SkipReasons.

the mod_perl test suite continues to run, as does the perl-framework, so
nothing (that I can see at least) should be broken.

anyway, comments welcome, as well as documentation - I couldn't decide where
to add the have stuff so I just didn't do anything.

--Geoff

Re: [PATCH] new need functions

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:

+1, with the small addition to the doc, thanks Geoff!

> -Functions that can be used as a last argument to the extended plan():
> +Functions that can be used as a last argument to the extended plan().
> +Note that for each C<need_*> function there is a C<have_*> equivalent
> +that performs the exact same function except that it is designed to
> +be used outside of C<plan()>.  

C<need_*> functions have the side effect of generating skip messages, if 
the test is skipped.  C<have_*> functions don't have this side effect.

> In other words, use C<need_apache()>
> +with C<plan()> to decide whether a test will run, but C<have_apache()>
> +within test logic to adjust expectations based on older or newer
> +server versions.



-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [PATCH] new need functions

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> I'd suggest to simply explain that there are have_ and need_ functions
> at the beginning of that section that explains need_* ones. And one
> should use need_* inside plan(), because of the skip messages. Otherwise
> use have_*.

ok, done.

> 
> Please don't commit w/o the docs. Once it's committed, the docs are most
> likely will be forgotten.

of course, no reminder necessary :)

> 
> You don't want to remember to update two places when you add new
> functions. So there should be a need* functions array and when you
> populate the @EXPORT list you generate the have* list. Also there should
> be no have() function, but only need(). The rest map need_* => have_*.

good idea, done.

> 
> Next you can use that have* list to generate the actual functions on the
> fly, similar to the generation of the subs similar to log levels subs in
> Apache::TestTrace. So you don't really need AUTOLOAD. It'll take the
> same amount of code w/o AUTOLOAD.

except that the autoload code is already written :)

> 
>> +sub AUTOLOAD {
>> +
>> +    use vars qw($AUTOLOAD @SkipReasons);
> 
> 
> haven't you declared the two at the top of Test.pm already?

sorry, leftover debugging foo.


> why not just:
> 
>      local @SkipReasons;
>      return $cv->(@_);

yeah, that's better.

new patch attached.

--Geoff

Re: [PATCH] new need functions

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> hi all
> 
> ok, attached is a patch that implements the new need variants and alters the
> old have variants.  basically, all I did was a global rename of have to
> need, then implement the have routines in terms of need with the AutoLoader.
>  I thought this made a bit more sense than redefining all of those
> subroutines again when the only difference was simply not populating
> @SkipReasons.
> 
> the mod_perl test suite continues to run, as does the perl-framework, so
> nothing (that I can see at least) should be broken.
> 
> anyway, comments welcome, as well as documentation - I couldn't decide where
> to add the have stuff so I just didn't do anything.

I'd suggest to simply explain that there are have_ and need_ functions 
at the beginning of that section that explains need_* ones. And one 
should use need_* inside plan(), because of the skip messages. Otherwise 
use have_*.

Please don't commit w/o the docs. Once it's committed, the docs are most 
likely will be forgotten.

You don't want to remember to update two places when you add new 
functions. So there should be a need* functions array and when you 
populate the @EXPORT list you generate the have* list. Also there should 
be no have() function, but only need(). The rest map need_* => have_*.

Next you can use that have* list to generate the actual functions on the 
fly, similar to the generation of the subs similar to log levels subs in 
Apache::TestTrace. So you don't really need AUTOLOAD. It'll take the 
same amount of code w/o AUTOLOAD.

> +sub AUTOLOAD {
> +
> +    use vars qw($AUTOLOAD @SkipReasons);

haven't you declared the two at the top of Test.pm already?

> +    (my $method) = $AUTOLOAD =~ m/.*::(.*)/;
> +
> +    return unless $method =~ m/^have/;
> +
> +    $method =~ s/^have/need/;
> +
> +    if (my $cv = Apache::Test->can($method)) {
> +        my @skip = @SkipReasons;
> +        my $rc = $cv->(@_);
> +        @SkipReasons = @skip;
> +        return $rc;

why not just:

      local @SkipReasons;
      return $cv->(@_);

> +    }
> +    else {
> +        die "could not find function $AUTOLOAD";
> +    } 
> +}
> +


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com