hi all I've managed to figure out at least preliminary support for using Test::More as the backend for Apache::Test. attached is a patch as well as a tarball that uses a few Test::More features in it. I may have missed a few of the finer features of Test::More, but it seems to do what I need it to, namely allowing the use of Test::More from server-side (t/response/TestFoo/foo.pm) tests as well as allowing the existing mod_perl-2.0 test suite to run unaltered.
feedback welcome. --Geoff
Index: lib/Apache/Test.pm =================================================================== RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/Test.pm,v retrieving revision 1.79 diff -u -r1.79 Test.pm --- lib/Apache/Test.pm 19 Apr 2004 02:38:58 -0000 1.79 +++ lib/Apache/Test.pm 26 Apr 2004 17:10:36 -0000 @@ -17,7 +17,6 @@ use strict; use warnings FATAL => 'all'; -use Test qw(ok skip); use Exporter (); use Config; use Apache::TestConfig (); @@ -46,6 +45,41 @@ } my $Config; +my $plan; +my @testmore = (); + +sub import { + my $class = shift; + + if ($_[0] and $_[0] =~ m/^-withtestmore/) { + # special hoops for Test::More support + + $plan = eval { + + require Test::More; + + # required for Test::More::import() and Apache::Test::plan() + @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)); + $plan = \&Test::plan; + } + + $class->export_to_level(1, undef, @_ ? @_ : @EXPORT); +} sub config { $Config ||= Apache::TestConfig->thaw; @@ -61,7 +95,7 @@ if (%SubTests and not $SubTests{ $Test::ntest }) { for my $n (1..$nok) { - skip "skipping this subtest", 0; + skip("skipping this subtest", 0); } return; } @@ -78,10 +112,18 @@ #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) { + require Test::Builder; + Test::Builder->output(\*STDOUT); + Test::Builder->failure_output(\*STDOUT); + Test::Builder->todo_output(\*STDOUT); + } + else { + $Test::TESTOUT = \*STDOUT; + $Test::planned = 0; + $Test::ntest = 1; + %Test::todo = (); + } } sub init_test_pm { @@ -170,7 +212,7 @@ } @SkipReasons = (); # reset - Test::plan(@_); + $plan->(@_, @testmore); } sub have { @@ -757,6 +799,29 @@ 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 replacing I<Test> with I<Test::More> entirely, and as such +is considered experimental at this time. + +Nevertheless, 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 { + + 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 the I<Test::More> framework +instead of the I<Test.pm> framework behind the scenes. Note that you are +not required to C<use Test::More> yourself with the C<-withtestmore> option. =head1 Apache::TestToString Class
testmore-test.tar.gz
Description: GNU Zip compressed data