hi all... michael schwern is very close to releasing Test::More 0.49, which is the first version of Test::More that we can use as the server-backend for Apache::Test.
I would like to integrate the Test::More foo into A-T as soon as 0.49 comes out. so, if you are interested in Test::More support and have some free tuits, I would appreciate some feedback on the work I have thus far. the first thing to do is download the latest Test::More http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/Test-Simple-0.48_02.tar.gz which schwern said is really the release candidate for 0.49. then, apply the attached patch and let me know how the tests turn out. really, I know that the Apache/Test.pm patch works, so if you have test failures it is more likely due to the test setup itself - I didn't want to move from Apache::TestRun to Apache::TestRunPerl so I needed to set up some of the mod_perl specific things myself. hopefully I got most of them right :) the tests pass successfully for me for apache 1.3 and 2.0, both with and without mod_perl installed (well, they don't run with without mod_perl but they don't implode either ;) anyway, as I've mentioned before, I've been using Test::More as the backend for a while now on a corporate project and it rocks, so I'm excited to port it over when 0.49 is official. 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.90 diff -u -r1.90 Test.pm --- lib/Apache/Test.pm 4 Aug 2004 19:07:06 -0000 1.90 +++ lib/Apache/Test.pm 5 Aug 2004 14:20:06 -0000 @@ -17,7 +17,6 @@ use strict; use warnings FATAL => 'all'; -use Test qw(ok skip); use Exporter (); use Config; use Apache::TestConfig (); @@ -52,6 +51,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; @@ -67,7 +108,7 @@ if (%SubTests and not $SubTests{ $Test::ntest }) { for my $n (1..$nok) { - skip "skipping this subtest", 0; + skip("skipping this subtest", 0); } return; } @@ -84,10 +125,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 { @@ -177,7 +234,7 @@ } @SkipReasons = (); # reset - Test::plan(@_); + $real_plan->(@_, @testmore); # add to Test.pm verbose output print "# Using Apache/Test.pm version $VERSION\n"; @@ -826,6 +883,41 @@ 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::Builder> 0.18_01, available in I<Test::Simple> +version 0.48_01 on CPAN, 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 Index: lib/Apache/TestHarness.pm =================================================================== RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestHarness.pm,v retrieving revision 1.18 diff -u -r1.18 TestHarness.pm --- lib/Apache/TestHarness.pm 4 Mar 2004 05:51:31 -0000 1.18 +++ lib/Apache/TestHarness.pm 5 Aug 2004 14:20:06 -0000 @@ -63,8 +63,13 @@ sub run_t { my($self, $file) = @_; my $ran = 0; - my $lib = catfile Apache::Test::vars('top_dir'), qw(Apache-Test lib); - my $cmd = qq[$^X -Mlib="$lib" $file]; + # so we can find Apache/Test.pm from both the perl-framework + # and Apache-Test. note that IS_APACHE_TEST_BUILD returns + # true for the perl-framework as well + my $lib = join ':', + catfile(Apache::Test::vars('top_dir'), qw(Apache-Test lib)), + catfile(Apache::Test::vars('top_dir'), 'lib'); + my $cmd = qq[PERL5LIB="$lib" $^X $file]; my $h = Symbol::gensym(); open $h, "$cmd|" or die "open $cmd: $!"; Index: t/conf/extra.conf.in =================================================================== RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/t/conf/extra.conf.in,v retrieving revision 1.3 diff -u -r1.3 extra.conf.in --- t/conf/extra.conf.in 27 Jun 2004 18:38:57 -0000 1.3 +++ t/conf/extra.conf.in 5 Aug 2004 14:20:06 -0000 @@ -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> + + --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ t/more/all.t 2004-08-05 07:17:47.000000000 -0700 @@ -0,0 +1,28 @@ +# 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/. --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ t/more/01testpm.t 2004-08-05 07:17:22.000000000 -0700 @@ -0,0 +1,8 @@ +# 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"; + --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ t/more/02testmore.t 2004-08-05 07:17:27.000000000 -0700 @@ -0,0 +1,8 @@ +# 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"; + --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ t/more/03testpm.t 2004-08-05 07:17:31.000000000 -0700 @@ -0,0 +1,8 @@ +# 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"; + --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ t/more/04testmore.t 2004-08-05 07:17:35.000000000 -0700 @@ -0,0 +1,8 @@ +# 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"; + --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ t/response/TestMore/testmorepm.pm 2004-08-05 06:43:16.000000000 -0700 @@ -0,0 +1,21 @@ +package TestMore::testmorepm; + +use strict; +use warnings FATAL => qw(all); + +use Test::More; +use Apache::Test qw(-withtestmore); + +sub handler { + + plan shift, tests => 2; + + is (1, 1, 'called Test::More::is()'); + + like ('wow', qr/wow/, 'called Test::More::like()'); + + 0; + +} + +1; --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ t/response/TestMore/testpm.pm 2004-08-05 06:40:14.000000000 -0700 @@ -0,0 +1,18 @@ +package TestMore::testpm; + +use strict; +use warnings FATAL => qw(all); + +use Apache::Test; +use Apache::TestUtil; + +sub handler { + + plan shift, tests => 1; + + ok t_cmp(1, 1, 'called Apache::Test::ok()'); + + 0; +} + +1; --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ t/conf/modperl_extra.pl.in 2004-08-05 07:12:54.000000000 -0700 @@ -0,0 +1,13 @@ +use strict; +use warnings FATAL => qw(all); + +use File::Spec (); + +use lib (); # empty so we can calculate the lib to use + +my @libs = (File::Spec->catfile('@ServerRoot@', 'response'), + File::Spec->catfile('@ServerRoot@', qw(.. lib))); + +lib->import(@libs); + +1;