You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-cvs@httpd.apache.org by ge...@apache.org on 2004/10/15 06:11:39 UTC

cvs commit: httpd-test/perl-framework/Apache-Test/t/more 01testpm.t 02testmore.t 03testpm.t 04testmore.t all.t

geoff       2004/10/14 21:11:39

  Modified:    perl-framework/Apache-Test Changes
               perl-framework/Apache-Test/lib/Apache Test.pm
               perl-framework/Apache-Test/t/conf extra.conf.in
  Added:       perl-framework/Apache-Test/t/more 01testpm.t 02testmore.t
                        03testpm.t 04testmore.t all.t
  Log:
  add -withtestmore import action, which allows Test::More >= 0.49
  to replace Test.pm as the engine for server-side tests for
  
  Revision  Changes    Path
  1.179     +4 -0      httpd-test/perl-framework/Apache-Test/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/Changes,v
  retrieving revision 1.178
  retrieving revision 1.179
  diff -u -r1.178 -r1.179
  --- Changes	12 Oct 2004 19:20:07 -0000	1.178
  +++ Changes	15 Oct 2004 04:11:39 -0000	1.179
  @@ -14,6 +14,10 @@
   add 'testcover' make target for running tests with Devel::Cover
   [Geoffrey Young]
   
  +add -withtestmore import action, which allows Test::More >= 0.49
  +to replace Test.pm as the engine for server-side tests for
  +[Geoffrey Young]
  +
   
   
   
  
  
  
  1.104     +100 -7    httpd-test/perl-framework/Apache-Test/lib/Apache/Test.pm
  
  Index: Test.pm
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/Test.pm,v
  retrieving revision 1.103
  retrieving revision 1.104
  diff -u -r1.103 -r1.104
  --- Test.pm	12 Oct 2004 12:32:34 -0000	1.103
  +++ Test.pm	15 Oct 2004 04:11:39 -0000	1.104
  @@ -17,7 +17,6 @@
   use strict;
   use warnings FATAL => 'all';
   
  -use Test qw(ok skip);
   use Exporter ();
   use Config;
   use Apache::TestConfig ();
  @@ -51,6 +50,48 @@
   }
   
   my $Config;
  +my $real_plan;
  +my @testmore;
  +
  +sub import {
  +    my $class = shift;
  +
  +    # once Test::More always Test::More until plan() is called
  +    if (($_[0] and $_[0] =~ m/^-withtestmore/) || @testmore) {
  +        # special hoops for Test::More support
  +
  +        $real_plan = eval { 
  +
  +            require Test::More; 
  +
  +            no warnings qw(numeric);
  +            Test::Builder->VERSION('0.18_01');
  +
  +            # required for Test::More::import() and Apache::Test::plan()
  +            # if we don't do this, Test::More exports plan() anyway
  +            # and we get collisions.  go figure.
  +            @testmore = (import => [qw(!plan)]);
  +
  +            Test::More->import(@testmore);
  +
  +            \&Test::More::plan;
  +        } or die "-withtestmore error: $@";
  +
  +        # clean up arguments to export_to_level
  +        shift;
  +        @EXPORT = (@test_more_exports, @Test::More::EXPORT);
  +    }
  +    else {
  +        # the default - Test.pm support
  +
  +        require Test;
  +        Test->import(qw(ok skip));
  +        @testmore = ();               # reset, just in case.
  +        $real_plan = \&Test::plan;
  +    }
  +
  +    $class->export_to_level(1, undef, @_ ? @_ : @EXPORT);
  +}
   
   sub config {
       $Config ||= Apache::TestConfig->thaw->httpd_config;
  @@ -73,7 +114,7 @@
   
       if (%SubTests and not $SubTests{ $Test::ntest }) {
           for my $n (1..$nok) {
  -            skip "skipping this subtest", 0;
  +            skip("skipping this subtest", 0);
           }
           return;
       }
  @@ -90,10 +131,26 @@
   
   #so Perl's Test.pm can be run inside mod_perl
   sub test_pm_refresh {
  -    $Test::TESTOUT = \*STDOUT;
  -    $Test::planned = 0;
  -    $Test::ntest = 1;
  -    %Test::todo = ();
  +    if (@testmore) {
  +        
  +        Test::Builder->reset;
  +
  +        Test::Builder->output(\*STDOUT);
  +        Test::Builder->todo_output(\*STDOUT);
  +
  +        # this is STDOUT because Test::More seems to put 
  +        # most of the stuff we want on STDERR, so it ends
  +        # up in the error_log instead of where the user can
  +        # see it.   consider leaving it alone based on
  +        # later user reports.
  +        Test::Builder->failure_output(\*STDOUT);
  +    }
  +    else {
  +        $Test::TESTOUT = \*STDOUT;
  +        $Test::planned = 0;
  +        $Test::ntest = 1;
  +        %Test::todo = ();
  +    }
   }
   
   sub init_test_pm {
  @@ -183,7 +240,7 @@
       }
       @SkipReasons = (); # reset
   
  -    Test::plan(@_);
  +    $real_plan->(@_, @testmore);
   
       # add to Test.pm verbose output
       print "# Using Apache/Test.pm version $VERSION\n";
  @@ -862,6 +919,42 @@
       plan tests => 1;           # Test::More::plan()
   
       ok ('yes', 'testing ok');  # Test::More::ok()
  +
  +Now, while this works fine for standard client-side tests 
  +(such as C<t/basic.t>), the more advanced features of I<Apache::Test>
  +require using I<Test::More> as the sole driver behind the scenes.
  +
  +Should you choose to use I<Test::More> as the backend for
  +server-based tests (such as C<t/response/TestMe/basic.pm>) you will
  +need to use the C<-withtestmore> action tag:
  +
  +    use Apache::Test qw(-withtestmore);
  +
  +    sub handler {
  +
  +        my $r = shift;
  +
  +        plan $r, tests => 1;           # Test::More::plan() with
  +                                       # Apache::Test features
  +
  +        ok ('yes', 'testing ok');      # Test::More::ok()
  +    }
  +
  +C<-withtestmore> tells I<Apache::Test> to use I<Test::More>
  +instead of I<Test.pm> behind the scenes.  Note that you are not
  +required to C<use Test::More> yourself with the C<-withtestmore>
  +option and that the C<use Test::More tests =E<gt> 1> syntax
  +may have unexpected results.  
  +
  +Note that I<Test::More> version 0.49, available within the
  +I<Test::Simple> 0.49 distribution on CPAN, or greater is required
  +to use this feature.
  +
  +Because I<Apache:Test> was initially developed using I<Test> as
  +the framework driver, complete I<Test::More> integration is
  +considered experimental at this time - it is supported as best as
  +possible but is not guaranteed to be as stable as the default I<Test>
  +interface at this time.
   
   =head1 Apache::TestToString Class
   
  
  
  
  1.4       +28 -0     httpd-test/perl-framework/Apache-Test/t/conf/extra.conf.in
  
  Index: extra.conf.in
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/t/conf/extra.conf.in,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- extra.conf.in	27 Jun 2004 18:38:57 -0000	1.3
  +++ extra.conf.in	15 Oct 2004 04:11:39 -0000	1.4
  @@ -4,3 +4,31 @@
   <IfModule mod_alias.c>
     Redirect /redirect http://@ServerName@/redirected/
   </IfModule>
  +
  +<IfModule mod_perl.c>
  +  <IfDefine APACHE2>
  +    PerlModule Apache2
  +  </IfDefine>
  +
  +  <Location /TestMore__testpm>
  +    SetHandler perl-script
  +    <IfDefine APACHE2>
  +      PerlResponseHandler TestMore::testpm
  +    </IfDefine>
  +    <IfDefine APACHE1>
  +      PerlHandler TestMore::testpm
  +    </IfDefine>
  +  </Location>
  +
  +  <Location /TestMore__testmorepm>
  +    SetHandler perl-script
  +    <IfDefine APACHE2>
  +      PerlResponseHandler TestMore::testmorepm
  +    </IfDefine>
  +    <IfDefine APACHE1>
  +      PerlHandler TestMore::testmorepm
  +    </IfDefine>
  +  </Location>
  +</IfModule>
  +
  +
  
  
  
  1.1                  httpd-test/perl-framework/Apache-Test/t/more/01testpm.t
  
  Index: 01testpm.t
  ===================================================================
  # see the description in t/more/all.t
  
  use strict;
  use warnings FATAL => qw(all);
  
  use Apache::TestRequest 'GET_BODY_ASSERT';
  print GET_BODY_ASSERT "/TestMore__testpm";
  
  
  
  
  1.1                  httpd-test/perl-framework/Apache-Test/t/more/02testmore.t
  
  Index: 02testmore.t
  ===================================================================
  # see the description in t/more/all.t
  
  use strict;
  use warnings FATAL => qw(all);
  
  use Apache::TestRequest 'GET_BODY_ASSERT';
  print GET_BODY_ASSERT "/TestMore__testmorepm";
  
  
  
  
  1.1                  httpd-test/perl-framework/Apache-Test/t/more/03testpm.t
  
  Index: 03testpm.t
  ===================================================================
  # see the description in t/more/all.t
  
  use strict;
  use warnings FATAL => qw(all);
  
  use Apache::TestRequest 'GET_BODY_ASSERT';
  print GET_BODY_ASSERT "/TestMore__testpm";
  
  
  
  
  1.1                  httpd-test/perl-framework/Apache-Test/t/more/04testmore.t
  
  Index: 04testmore.t
  ===================================================================
  # see the description in t/more/all.t
  
  use strict;
  use warnings FATAL => qw(all);
  
  use Apache::TestRequest 'GET_BODY_ASSERT';
  print GET_BODY_ASSERT "/TestMore__testmorepm";
  
  
  
  
  1.1                  httpd-test/perl-framework/Apache-Test/t/more/all.t
  
  Index: all.t
  ===================================================================
  # skip all the Test::More tests if Test::More is
  # not of a sufficient version;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  
  plan tests => 1, (need_min_module_version(qw(Test::More 0.48_01)) &&
                    need_module('mod_perl.c'));
  
  ok 1;
  
  
  # the t/more/ directory is testing a few things.
  #
  # first, it is testing that the special
  #    Apache::Test qw(-withtestmore);
  # import works, which allows Apache::Test to use
  # Test::More as the backend (in place of Test.pm)
  # for server-side tests.
  #
  # secondly, it is testing that we can intermix
  # scripts that use Test.pm and Test::More as the
  # backend, which was a bug that needed to be worked
  # around in early implementations of -withtestmore.
  # hence the reason for the specific ordering of the
  # tests in t/more/.
  
  
  

Re: cvs commit: httpd-test/perl-framework/Apache-Test/t/more

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

geoff@apache.org wrote:
> geoff       2004/10/14 21:11:39
> 
>   Modified:    perl-framework/Apache-Test Changes
>                perl-framework/Apache-Test/lib/Apache Test.pm
>                perl-framework/Apache-Test/t/conf extra.conf.in
>   Added:       perl-framework/Apache-Test/t/more 01testpm.t 02testmore.t
>                         03testpm.t 04testmore.t all.t
>   Log:
>   add -withtestmore import action, which allows Test::More >= 0.49
>   to replace Test.pm as the engine for server-side tests

Test::Simple 0.49 was just announced this evening, so I committed the work
that I've had sitting around just waiting for the announcement.

I know that the tests probably need some work, but the underlying
Apache/Test.pm functionality is pretty solid - we've been using it
internally for the past few months now and haven't seen any issues.

--Geoff