httpd-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: cvs commit: httpd-test/perl-framework/t/apache getfile.t
Date Thu, 22 Nov 2001 02:41:25 GMT
On 21 Nov 2001 dougm@apache.org 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<Test::skip>, see I<Test.pm> 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:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Mime
View raw message