> The problem appears to be due to headers not being sent when using > Test::More. I found the code in Apache::Test which initializes a handler > when `plan $r, tests => 10` is called.
you can't use Test::More on the server side (that is, from a handler, such as you have here). at least not with the current Apache-Test. to do that, you need to apply the attached patch - it may have some fuzz due to a change that I just implemented this week, but I have been using it for a few months now and haven't had any problems (once I figured out all the issues, that is). so, apply the patch and read the docs in the patch and you should be good to go. if you have trouble getting it to apply I'll whip up a current one next week. oh, and keep in mind that until Test::More goes official with the features in the (required) development version this will _not_ get integrated into Apache-Test. that's not to say I haven't found it stable, but rather that we can't integrate features into our stable software that depend on an external development API. --Geoff
Index: Apache/Test.pm =================================================================== RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/Test.pm,v retrieving revision 1.83 diff -u -r1.83 Test.pm --- Apache/Test.pm 1 Jun 2004 18:21:11 -0000 1.83 +++ Apache/Test.pm 2 Jun 2004 00:49:20 -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,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; @@ -61,7 +102,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 +119,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 { @@ -171,7 +228,7 @@ } @SkipReasons = (); # reset - Test::plan(@_); + $real_plan->(@_, @testmore); } sub have { @@ -783,6 +840,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