I've been working at reworking some of the apr
tests so that they can also function as apr-ext
tests, with as much common code as possible.
I have a working set, but before getting into
specifics, thought it'd be good to discuss some
of the design issues first.
As Stas suggested in some earlier messages,
one could put the common tests in one package,
and then call it from both t/apr/ and t/apr-ext/.
So the simplest tests (eg, constants.t), would
look like:
==============================================
# file t/apr-ext/constants.t
use lib qw(t);
require aprlib::constants;
aprlib::constants::test();
==============================================
for the t/apr-ext/ tests, and
==============================================
# file t/apr/constants.t
use lib qw(t);
require aprlib::constants;
aprlib::constants::test();
==============================================
for the t/apr/ tests, where the common
tests use
=============================================
# file t/aprlib/constants.pm
use Test;
# etc
sub test {
plan tests => 5;
ok 1;
# etc
}
1;
============================================
So the first question I had - is there a better
name and/or location than "t/aprlib/" to put
in the common code?
However, all the other tests require something
more complex, as the corresponding t/apr/ tests
use $r explicitly. What about the following
model? For some test foo, one has
==============================================
# file t/apr-ext/foo.t
use lib qw(t);
require aprlib::foo;
aprlib::foo::test();
==============================================
for the t/apr-ext/ tests, and for the
t/apr/ tests, the corresponding response
=============================================
# file t/response/TestAPR/foo.pm
package TestAPR::foo;
use Apache::Test;
use lib qw(t);
require aprlib::foo;
# etc
sub handler {
my $r = shift;
# run common tests, and plan for 5 additional ones
aprlib::foo::test(r => $r, extra => 5);
# run 5 additional mod_perl specific tests
Apache::OK;
}
1;
=================================================
Here, the common tests look like
=================================================
# file t/aprlib/foo.pm
package aprlib::foo;
use Apache::Test;
# etc
sub test {
my %args = @_;
my $r = $args{r};
my $extra = $args{extra} || 0;
if ($r) {
plan $r, tests => 55 + $extra, some_possible_condition;
}
else {
plan tests => 55, some_possible_condition;
}
# some of the tests may want a pool
my $pool = $r ? $r->pool : APR::Pool->new();
# some of the tests may use $r->notes for a table
my $table = $r ? $r->notes : APR::Table::make($pool, 2);
# etc
}
1;
============================================================
Something that may be simpler is to use, within the
response, Apache::Test's test_pm_refresh: the apr-ext
test is the same, whereas the response would be
==========================================================
# file t/response/TestAPR/foo.pm
package TestAPR::foo;
use Apache::Test;
use lib qw(t);
require aprlib::foo;
# etc
sub handler {
my $r = shift;
# run common tests, and then run 5 additional ones
aprlib::foo::test($r);
# run 5 additional mod_perl specific tests
Apache::Test::test_pm_refresh;
plan $r, tests => 5, some_possible_condition;
# run 5 more tests
Apache::OK;
}
1;
=================================================
where here the common tests are
=================================================
# file t/aprlib/foo.pm
package aprlib::foo;
use Apache::Test;
# etc
sub test {
my $r = shift;
if ($r) {
plan $r, tests => 55, some_possible_condition;
}
else {
plan tests => 55, some_possible_condition;
}
# some of the tests may want a pool
my $pool = $r ? $r->pool : APR::Pool->new();
# some of the tests may use $r->notes for a table
my $table = $r ? $r->notes : APR::Table::make($pool, 2);
# etc
}
1;
============================================================
When running the tests using the latter, the output looks
like
t\apr\foo....ok 55/55Test header seen more than once!
t\apr\foo....ok
All tests successful
which may be a bit confusing?
I guess this could also be made simpler by, in the
common tests, always using APR::Pool and APR::Table,
but perhaps it would be good to test $r->pool and
$r->notes in an httpd environment?
--
best regards,
randy
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]