Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: Dev

test ideas

 

 

ModPerl dev RSS feed   Index | Next | Previous | View Threaded


bcm at maz

Jun 24, 2001, 5:11 AM

Post #1 of 5 (1213 views)
Permalink
test ideas

fwiw, i've come up with a couple of other useful shorthand
routines for my Wombat::Test package:

sub have_lib {
for (@_) {
unless (eval "require $_") {
$@ = "$_ not found\n" if $@ =~ /^Can't locate/;
return undef;
}
}
return 1;
}

sub skip_all {
my $msg = $_[0] ? " # Skipped: $_[0]" : '';
print "1..0$msg\n";
exit;
}

they allow me to do stuff like this at the beginning of each
test file:

skip_all $@ unless have_lib qw(mod_perl Foo Apache::FakeRequest);
plan tests => 6;

which gives this output:

connector/apache/apache.skipped: Foo not found


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl


stas at stason

Jun 24, 2001, 5:20 AM

Post #2 of 5 (1191 views)
Permalink
Re: test ideas [In reply to]

On Sun, 24 Jun 2001, brian moseley wrote:

>
> fwiw, i've come up with a couple of other useful shorthand
> routines for my Wombat::Test package:
>
> sub have_lib {
> for (@_) {
> unless (eval "require $_") {
> $@ = "$_ not found\n" if $@ =~ /^Can't locate/;
> return undef;
> }
> }
> return 1;
> }

sometimes it's not 1:1 : e.g. see: Apache::TestRequest::have_lwp

but certainly this one looks a good candidate to go inside as it makes the
test framework API more generic. I'll let Doug to judge though.

> sub skip_all {
> my $msg = $_[0] ? " # Skipped: $_[0]" : '';
> print "1..0$msg\n";
> exit;
> }

already there more or less. See perldoc Apache::Test in cvs.

> they allow me to do stuff like this at the beginning of each
> test file:
>
> skip_all $@ unless have_lib qw(mod_perl Foo Apache::FakeRequest);
> plan tests => 6;
>
> which gives this output:
>
> connector/apache/apache.skipped: Foo not found

yes, but it reports only one missing module even if two are missing :)
better to report all the missing pieces at once. but it should be in one
string or Test::Harness will say: 'for various reasons' :)



_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas [at] stason http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl


bcm at maz

Jun 24, 2001, 5:30 AM

Post #3 of 5 (1189 views)
Permalink
Re: test ideas [In reply to]

On Sun, 24 Jun 2001, Stas Bekman wrote:

> already there more or less. See perldoc Apache::Test in
> cvs.

my "skip_all unless have_lib" is just shorthand for a very
common requirement. it shouldn't replace the more general,
powerful and verbose "plan unless condition", but it does
save a lot of typing in many instances.

> yes, but it reports only one missing module even if two
> are missing :)

yeah. that's good enough for me. if you want to make it
report all of them, go for it.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl


dougm at covalent

Jun 25, 2001, 4:26 PM

Post #4 of 5 (1188 views)
Permalink
Re: test ideas [In reply to]

On Sun, 24 Jun 2001, brian moseley wrote:

>
> fwiw, i've come up with a couple of other useful shorthand
> routines for my Wombat::Test package:
...
> they allow me to do stuff like this at the beginning of each
> test file:
>
> skip_all $@ unless have_lib qw(mod_perl Foo Apache::FakeRequest);
> plan tests => 6;

that's cool, 1.x has similar:
skip_test unless have_module 'Foo';

i just found it shorter/cleaner to write:

plan tests => 6, \&condition;

especially since &condition can be used in multiple tests (like &have_lwp
is), without having to duplicate the various condition code in each .t

i'm totally fine with adding these routines to the Apache-Test kit,
might as well keep the same names as 1.x.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl


bcm at maz

Jun 25, 2001, 6:08 PM

Post #5 of 5 (1191 views)
Permalink
Re: test ideas [In reply to]

On Mon, 25 Jun 2001, Doug MacEachern wrote:

> that's cool, 1.x has similar:
> skip_test unless have_module 'Foo';

yeah i knew i horked the concept from you somewhere along
the line :)

> i just found it shorter/cleaner to write:
>
> plan tests => 6, \&condition;
>
> especially since &condition can be used in multiple
> tests (like &have_lwp is), without having to duplicate
> the various condition code in each .t

yeah, having multiple options is nice :)

i have a TestFixture class that calls plan internally based
on a dynamically built test list, so i can't actually call
plan in the test script, so having skip_all is very handy.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl

ModPerl dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.