according to the Apache::Test::plan's docs, it extends Test::plan and
passes all the args to Test::plan, but the last one, if it's a reference
-- that's where the extended logic is hidden. But the problem is that if
you look at the Test's manpage, it says:

  BEGIN { plan tests => 14, todo => [3,4] }

therefore if in the Apache::Test framework's test, I say:

  plan tests => 14, todo => [3,4];

the extended logic will be triggered (the last arg is a ref) and the test
will fail, since Test::plan won't get the ballanced %arg and other
reasons.

Since Test::plan always expects a ballanced %arg, I've fixed the logic of
Apache::Test::plan to trigger our extended logic only if @_ is not a
quotient of 2 (not a ballanced hash).

This eliminates the need for the test_module() hack. The patch fixes one
test, but a simple s/// will do the rest in the mod_perl and httpd-test
reps.

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.23
diff -u -r1.23 Test.pm
--- Apache-Test/lib/Apache/Test.pm      2001/09/10 17:22:13     1.23
+++ Apache-Test/lib/Apache/Test.pm      2001/09/18 03:10:06
@@ -9,7 +9,7 @@

 our @ISA = qw(Exporter);
 our @EXPORT = qw(ok skip sok plan have_lwp have_http11 have_cgi
-                 test_module have_module have_apache);
+                 have_module have_apache);
 our $VERSION = '0.01';

 our %SubTests;
@@ -71,23 +71,27 @@
 sub plan {
     init_test_pm(shift) if ref $_[0];

-    my $condition = pop @_ if ref $_[-1];
-    if ($condition) {
+    # extending Test::plan's functionality, by using the optional
+    # single value in @_ coming after a ballanced %hash which
+    # Test::plan expects
+    if (@_ % 2) {
+        my $condition = pop @_;
+        my $ref = ref $condition;
         my $meets_condition = 0;
-        if (ref($condition) eq 'CODE') {
-            #plan tests $n, \&has_lwp
-            $meets_condition = $condition->();
-        }
-        elsif (ref($condition) eq 'ARRAY') {
-            if (@$condition == 1 and $condition->[0] =~ /^([01])$/) {
-                #plan tests $n, test_module 'php4'
-                $meets_condition = $1
+        if ($ref) {
+            if ($ref eq 'CODE') {
+                #plan tests $n, \&has_lwp
+                $meets_condition = $condition->();
             }
-            else {
+            elsif ($ref eq 'ARRAY') {
                 #plan tests $n, [qw(php4 rewrite)];
                 $meets_condition = have_module($condition);
             }
         }
+        else {
+            # we have the verdict already: true/false
+            $meets_condition = $condition ? 1 : 0;
+        }

         unless ($meets_condition) {
             print "1..0\n";
@@ -120,11 +124,6 @@

 sub have_cgi {
     [have_module('cgi') || have_module('cgid')];
-}
-
-#sugar: plan tests => 1, test_module 'php4'
-sub test_module {
-    [have_module(@_)]
 }

 sub have_apache {
Index: t/protocol/eliza.t
===================================================================
RCS file: /home/cvs/modperl-2.0/t/protocol/eliza.t,v
retrieving revision 1.1
diff -u -r1.1 eliza.t
--- t/protocol/eliza.t  2001/09/06 02:45:13     1.1
+++ t/protocol/eliza.t  2001/09/18 03:10:06
@@ -10,7 +10,7 @@
                     'I feel like writing some tests today, you?',
                     'good bye');

-plan tests => 1 + @test_strings, test_module 'Chatbot::Eliza';
+plan tests => 1 + @test_strings, have_module 'Chatbot::Eliza';

 my $socket = Apache::TestRequest::vhost_socket('TestProtocol::eliza');


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



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to