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 CARRAY reference

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

 Same as ITest::skip, see ITest.pm 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-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-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: mailto:[EMAIL PROTECTED]

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-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 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 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/