Hi,
while testing 1.34rc1 I get these lines in the error_log.
Prototype mismatch: sub Apache::Test::ok ($;$$) vs ($;$) at
/home/r2/tmp/tmp3/Apache-Test-1.34-rc1/t/../lib/Apache/Test.pm line 88
Prototype mismatch: sub Apache::Test::skip ($;$$$) vs none at
/home/r2/tmp/tmp3/Apache-Test-1.34-rc1/t/../lib/Apache/Test.pm line 88
A look at the source reveals that import() imports these functions either from
Test::More or from Test. So if one calls AT -withtestmore the functions from
Test::More are loaded otherwise from Test.
But what happens if I use AT with and without testmore in the same
interpreter? (For larger projects this is probably the common case.)
$ perl -MApache::Test -MApache::Test=-withtestmore -le ''
Prototype mismatch: sub Apache::Test::ok ($;$$) vs ($;$) at
/opt/perl/lib/vendor_perl/5.12.1/x86_64-linux/Apache/Test.pm line 88
Prototype mismatch: sub Apache::Test::skip ($;$$$) vs none at
/opt/perl/lib/vendor_perl/5.12.1/x86_64-linux/Apache/Test.pm line 88
Prototype mismatch: sub main::ok ($;$$) vs ($;$) at -e line 0
Prototype mismatch: sub main::skip ($;$$$) vs none at -e line 0
while the other way around there is no error:
$ perl -MApache::Test=-withtestmore -MApache::Test -le ''
$
I believe this is a sign for a deeper problem. Can we really allow for
use Apache::Test qw/-withtestmore/;
and
use Apache::Test;
in the same interpreter?
The way it is currently implemented you might not get what you want. Test::ok
eats up to 3 parameters: the value to test, an optional value to compare with
and a test name. Test::More::ok eats only 2 parameters: a boolean value and a
name. So, I implement my first test w/o -wtm and use somewhere
ok $got, qr/\b(?:foo|bar)\b/, 'test for foo or bar';
Some time later I write another test where Test::More's is_deeply comes in
handy. So, that module is written with -wtm. Now it may happen that the ok()
function in my first test becomes suddenly Test::More::ok and the test
succeeds even if $got is 'blahblah'.
I thought about the -withtestmore option always as sort of lexical pragma. I
believe most people do. And the experts know that it's not a good idea to mix
-withtestmore and -withouttestmore in the same interpreter. I think I recall
running into such an issue with no time to investigate further.
How about implementing it as lexical pragma and let the user decide which
flavor to use?
package YY;
use strict;
use warnings;
use Exporter ();
our @ISA=(qw/Exporter/);
our @EXPORT=(qw/plan/);
sub simple {warn "simple"}
sub more {warn "more"}
sub import {
my $class=shift;
$^H{YY}=1 if grep $_ eq '-wtm', @_;
my @exp=grep $_ ne '-wtm', @_;
$class->export_to_level(1, undef, @exp ? @exp : @EXPORT);
}
sub unimport {
my $class=shift;
delete $^H{YY} if grep $_ eq '-wtm', @_;
}
sub plan {
((caller 0)[10]||{})->{YY} ? more : simple;
}
1;
$ perl -I. -e 'use strict; use YY; plan; {use YY qw/-wtm/; plan;}; plan; use
YY qw/-wtm/; plan; no YY qw/-wtm/; plan;'
simple at YY.pm line 9.
more at YY.pm line 10.
simple at YY.pm line 9.
more at YY.pm line 10.
simple at YY.pm line 9.
I know this breaks the current API. But I think the current implementation is
unfixable buggy.
Other options are drop -wtm and implement it as separate module
Apache::Test::More or make -wtm standard and drop Test.pm and the option. The
latter requires perl>=5.8.7.
I think this bug should not stop the current release cycle since it has always
been that way.
Thoughts?
Torsten Förtsch
--
Need professional modperl support? Hire me! (http://foertsch.name)
Like fantasy? http://kabatinte.net