Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-21 Thread Doug MacEachern
On Fri, 21 Dec 2001, Stas Bekman wrote:
 
> OK, here it is: I've finally called it skip_all() as it's a standalone
> function now.

cool, +1.  but would rather it still be called skip_unless()




Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-21 Thread Stas Bekman
On Tue, 4 Dec 2001, Doug MacEachern wrote:

> On Thu, 22 Nov 2001, Stas Bekman wrote:
>
> > I can extend it to engulf the plan() extension that we have added and then
> > the only function you will ever call with plan() is skip_unless. I
> > think this:
> >
> >   plan ..., skip_unless('cgi', 'lwp');
>
> there's no point in overloading plan anymore then.  we should just change
> it to:
>
> skip_unless(...);
>
> plan tests => $tests;
>
> and have skip_unless() print "1..0\n..."; exit; if conditions are not met.
>
> personally, i would rather keep the the current plan shorthand and change
> skip_unless to be called as it is above.

OK, here it is: I've finally called it skip_all() as it's a standalone
function now.

Index: Apache-Test/lib/Apache/Test.pm
===
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/Test.pm,v
retrieving revision 1.40
diff -u -r1.40 Test.pm
--- Apache-Test/lib/Apache/Test.pm  2001/12/18 00:47:03 1.40
+++ Apache-Test/lib/Apache/Test.pm  2001/12/21 09:34:43
@@ -11,7 +11,7 @@
 use vars qw(@ISA @EXPORT $VERSION %SubTests @SkipReasons);

 @ISA = qw(Exporter);
[EMAIL PROTECTED] = qw(ok skip sok plan skip_unless have_lwp have_http11
[EMAIL PROTECTED] = qw(ok skip sok plan skip_all have_lwp have_http11
  have_cgi have_module have_apache have_perl);
 $VERSION = '0.01';

@@ -138,17 +138,33 @@
 Test::plan(@_);
 }

-sub skip_unless {
-my $condition = shift;
-my $reason = shift || "no reason given";
-
-if (ref $condition eq 'CODE' and $condition->()) {
-return 1;
+sub skip_all {
+my $should_skip = 0;
+for my $cond (@_) {
+if (ref $cond eq 'HASH') {
+while (my($code, $reason) = each %$cond) {
+$reason = "no reason given" unless defined $reason;
+if (ref $code eq 'CODE' and $code->()) {
+next;
+}
+else {
+push @SkipReasons, $reason;
+$should_skip++;
+}
+}
+}
+else {
+$should_skip++ unless have_module($cond);
+}
 }
-else {
-push @SkipReasons, $reason;
-return 0;
+
+if ($should_skip) {
+my $reason = join ', ',
+@SkipReasons ? @SkipReasons : "no reason given";
+print "1..0 # skipped: $reason\n";
+exit; #XXX: Apache->exit
 }
+@SkipReasons = (); # reset
 }

 sub have_module {
@@ -321,11 +337,12 @@
   plan tests => 5, 0;

 But this won't hint the reason for skipping therefore it's better to
-use skip_unless():
+use skip_all()

-  plan tests => 5, skip_unless(sub { $a == $b }, "$a != $b");
+  skip_all({sub { $a == $b } => "$a != $b"}, 'LWP');
+  plan tests => 5;

-see skip_unless() for more info.
+see skip_all() for more info.

 =item * an C reference

@@ -364,16 +381,27 @@
 =item skip

 Same as I, see I documentation.
-
-=item skip_unless

-  skip_unless($cond_sub, $reason);
+=item skip_all

-skip_unless() is used with plan(), it executes C<$cond_sub> code
-reference and if it returns a false value C<$reason> gets printed as a
-reason for test skipping.
+  skip_all({sub {$a==$b} => "$a != $b!"
+   sub {$a==1}  => "$a != 1!"},
+  'LWP',
+  'cgi_d',
+   {sub {0} => "forced to be skipped"},
+ );
+
+skip_all() can be called before plan(), to decide whether to skip the
+whole test or not. plan() won't be reached if skip_all decides to skip
+the test.
+
+skip_all's argument is a list of things to test. The list can include
+scalars, which are passed to have_module(), and hash references. The
+hash references have condition code ref as a key and the reason for
+failure as a value. The condition code is run and if it fails the
+reason is used to explain the failure.

-see plan().
+Also see plan().

 =item test_pm_refresh


_
Stas Bekman JAm_pH  --   Just Another mod_perl Hacker
http://stason.org/  mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-05 Thread Rodent of Unusual Size
ebinc wrote:
> 
> Does any one know how to unsubscribe from this list? Ive been
> on the site but cannot find were it is

In the mail header you'll see:

list-unsubscribe: 

which is the Sum of All Wisdom for this question. :-)
-- 
#kenP-)}

Ken Coar, Sanagendamgagwedweinini  http://Golux.Com/coar/
Author, developer, opinionist  http://Apache-Server.Com/

"All right everyone!  Step away from the glowing hamburger!"


Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-05 Thread ebinc
Does any one know how to unsubscribe from this list? Ive been on the site
but cannot find were it is you guys are way out of my league Im just a
beginner
- Original Message -
From: Doug MacEachern <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, December 04, 2001 2:10 PM
Subject: Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t


> On Wed, 5 Dec 2001, Stas Bekman wrote:
>
> > having two places where the test can be told to skip is confusing.
>
> confusing to who?  have you forgotten the perl motto?
>
> > So you only want to preserve:
> >
> >plan tests => $tests, ['lwp', 'cgi'];
>
> and anything else that currently works, like:
>
> plan tests => $tests, \&have_foo;
>
> > i.e. the ref eq ARRAY part in the original implementation of overloaded
> > plan().
> >
> > Otherwise I think I can fit skip_unless as a function that can handle
> > *any* requirement. e.g.:
> >
> > +  skip_unless({sub {$a==$b} => "$a != $b!"
> > +   sub {$a==1}  => "$a != 1!"},
> > +  'LWP',
> > +  'cgi_d',
> > +   {sub {0} => "forced to be skipped"},
> > + );
> >
> > is that ok?
>
> making skip_unless more robust is fine.  but keep in mind, the common case
> uses the original shorthand syntax.  we only needed to add skip_unless for
> rare cases when the skip reason was unknown.
>
>



Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-04 Thread Doug MacEachern
On Wed, 5 Dec 2001, Stas Bekman wrote:
 
> having two places where the test can be told to skip is confusing.

confusing to who?  have you forgotten the perl motto?

> So you only want to preserve:
> 
>plan tests => $tests, ['lwp', 'cgi'];

and anything else that currently works, like:

plan tests => $tests, \&have_foo;
 
> i.e. the ref eq ARRAY part in the original implementation of overloaded 
> plan().
> 
> Otherwise I think I can fit skip_unless as a function that can handle 
> *any* requirement. e.g.:
> 
> +  skip_unless({sub {$a==$b} => "$a != $b!"
> +   sub {$a==1}  => "$a != 1!"},
> +  'LWP',
> +  'cgi_d',
> +   {sub {0} => "forced to be skipped"},
> + );
> 
> is that ok?

making skip_unless more robust is fine.  but keep in mind, the common case
uses the original shorthand syntax.  we only needed to add skip_unless for
rare cases when the skip reason was unknown.




Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-04 Thread Stas Bekman
Doug MacEachern wrote:
On Wed, 5 Dec 2001, Stas Bekman wrote:
 

I didn't get you? do you prefer to make this change and disengage skip 
stuff from plan:

 skip_unless(...);
 plan tests => $tests;
i'd like it if the current shorthand continues to work:
plan tests => $tests, ['lwp', 'cgi'];
i would not like it if the only option to plan was the return value of
skip_unless.  so if the skip_unless extensions do not fit into the
overloaded plan, then just detach it like you have above.  we only call it
in one .t at the moment (byterange), and i guess one more would call it if
the extension is made (getfile).
having two places where the test can be told to skip is confusing. So 
you only want to preserve:

  plan tests => $tests, ['lwp', 'cgi'];
i.e. the ref eq ARRAY part in the original implementation of overloaded 
plan().

Otherwise I think I can fit skip_unless as a function that can handle 
*any* requirement. e.g.:

+  skip_unless({sub {$a==$b} => "$a != $b!"
+   sub {$a==1}  => "$a != 1!"},
+  'LWP',
+  'cgi_d',
+   {sub {0} => "forced to be skipped"},
+ );
is that ok?
If so we advise users to use skip_unless() everywhere and [qw(foo bar)] 
as a shortcut.

_
Stas Bekman JAm_pH  --   Just Another mod_perl Hacker
http://stason.org/  mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-04 Thread Doug MacEachern
On Wed, 5 Dec 2001, Stas Bekman wrote:
 
> I didn't get you? do you prefer to make this change and disengage skip 
> stuff from plan:
> 
>   skip_unless(...);
>   plan tests => $tests;

i'd like it if the current shorthand continues to work:
plan tests => $tests, ['lwp', 'cgi'];

i would not like it if the only option to plan was the return value of
skip_unless.  so if the skip_unless extensions do not fit into the
overloaded plan, then just detach it like you have above.  we only call it
in one .t at the moment (byterange), and i guess one more would call it if
the extension is made (getfile).




Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-04 Thread Stas Bekman
Doug MacEachern wrote:
On Thu, 22 Nov 2001, Stas Bekman wrote:
 

I can extend it to engulf the plan() extension that we have added and then
the only function you will ever call with plan() is skip_unless. I
think this:
 plan ..., skip_unless('cgi', 'lwp');
there's no point in overloading plan anymore then.  we should just change
it to:
skip_unless(...);
plan tests => $tests;
and have skip_unless() print "1..0\n..."; exit; if conditions are not met.

sounds good.

personally, i would rather keep the the current plan shorthand and change
skip_unless to be called as it is above.

I didn't get you? do you prefer to make this change and disengage skip 
stuff from plan:

 skip_unless(...);
 plan tests => $tests;
or do you prefer:
plan ..., skip_unless('cgi', 'lwp');
_
Stas Bekman JAm_pH  --   Just Another mod_perl Hacker
http://stason.org/  mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-12-04 Thread Doug MacEachern
On Thu, 22 Nov 2001, Stas Bekman wrote:
 
> I can extend it to engulf the plan() extension that we have added and then
> the only function you will ever call with plan() is skip_unless. I
> think this:
> 
>   plan ..., skip_unless('cgi', 'lwp');

there's no point in overloading plan anymore then.  we should just change
it to:

skip_unless(...);

plan tests => $tests;

and have skip_unless() print "1..0\n..."; exit; if conditions are not met.

personally, i would rather keep the the current plan shorthand and change
skip_unless to be called as it is above.



Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t

2001-11-22 Thread Stas Bekman
On 21 Nov 2001 [EMAIL PROTECTED] wrote:

> dougm   01/11/21 13:21:33
>
>   Modified:perl-framework/t/apache getfile.t
>   Log:
>   switch to using a response callback to cut down on memory usage

>   +#XXX: howto plan ..., skip_unless(...) + have_module(...) ?
>   +push @Apache::Test::SkipReasons,
>   +  "dir $vars->{perlpod} doesn't exist"

I suggest the following patch. See the doc at the end. Basically it
eliminates the need to expose have_module(), while keeping it simple. And
will let us extend it in the future to add even more functionality.

I can extend it to engulf the plan() extension that we have added and then
the only function you will ever call with plan() is skip_unless. I
think this:

  plan ..., skip_unless('cgi', 'lwp');

is easier to grasp than:

  plan ..., ['cgi', 'lwp'];

How about that? If we do that you can have:

  skip_unless(
   { sub {test()}  => "something is missing",
 sub {test2()} => "something2 is missing",
   },
   \&have_lwp,
   'cgi',
   'Storable'
   { sub {test3()}  => "something3 is missing"}
);

Index: Apache-Test/lib/Apache/Test.pm
===
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/Test.pm,v
retrieving revision 1.33
diff -u -r1.33 Test.pm
--- Apache-Test/lib/Apache/Test.pm  2001/11/16 19:58:09 1.33
+++ Apache-Test/lib/Apache/Test.pm  2001/11/22 02:17:32
@@ -138,16 +138,28 @@
 }

 sub skip_unless {
-my $condition = shift;
-my $reason = shift || "no reason given";
+my @conditions = @_;

-if (ref $condition eq 'CODE' and $condition->()) {
-return 1;
-}
-else {
-push @SkipReasons, $reason;
-return 0;
+my $should_skip = 0;
+for my $cond (@conditions) {
+if (ref $cond eq 'HASH') {
+while (my($code, $reason) = each %$cond) {
+$reason = "no reason given" unless defined $reason;
+if (ref $code eq 'CODE' and $code->()) {
+next;
+}
+else {
+push @SkipReasons, $reason;
+$should_skip++;
+}
+}
+}
+else {
+$should_skip++ unless have_module($cond);
+}
 }
+
+return $should_skip ? 0 : 1;
 }

 sub have_module {
@@ -307,7 +319,7 @@
 But this won't hint the reason for skipping therefore it's better to
 use skip_unless():

-  plan tests => 5, skip_unless(sub { $a == $b }, "$a != $b");
+  plan tests => 5, skip_unless({sub { $a == $b } => "$a != $b"}, 'LWP');

 see skip_unless() for more info.

@@ -350,14 +362,22 @@
 Same as I, see I documentation.

 =item skip_unless
-
-  skip_unless($cond_sub, $reason);

-skip_unless() is used with plan(), it executes C<$cond_sub> code
-reference and if it returns a false value C<$reason> gets printed as a
-reason for test skipping.
+  skip_unless({sub {$a==$b} => "$a != $b!"
+   sub {$a==1}  => "$a != 1!"},
+  'LWP',
+  'cgi_d',
+   {sub {0} => "forced to be skipped"},
+ );
+
+skip_unless() is used with plan(), to decide whether to skip the test
+or not. Its argument is a list of things to test. The list can include
+scalars, which are passed to have_module() and hash references. The
+hash references have condition code ref as a key and the reason for
+failure as a value. The condition code is run and if it fails the
+reason is used to explain the failure.

-see plan().
+Also see plan().

 =item test_pm_refresh


_
Stas Bekman JAm_pH  --   Just Another mod_perl Hacker
http://stason.org/  mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/