Testing befuddlement
User:
afbach
Date: 4/7/2008 3:56 pm
Date: 4/7/2008 3:56 pm
Views: 96
Rating: 0
Rating: 0
Hey.
Background - trying to be able to 'make smoke' for parrot on a
relatively new install of opensuse. It wasn't working via cpan, so,
what the heck, I installed perl 5.10. Went back and started w/
install Bundle::Test and ran into lots of missing reqs and after a day
or so, got it down to a few final messes (including needing to install
tidy/libtidy from cvs). One of which was WWW::Mechanize::Pluggable and
that seemed to be having issues w/ Test::Taint. Well, Test::Taint
wasn't installed, so I installed that and, from the cpan/build/W:B:P
dir found
...
t/taint......You tried to run a test without a plan at t/taint.t line 17.
Okay, this is part of where I don't quite get testing but taint.t has:
#!perl -T
use warnings;
use strict;
use Test::More;
use URI;
eval "use Test::Taint";
($^O) = ($^O =~ /.*/);
plan skip_all => "Test::Taint required for checking taintedness" if $@;
plan tests=>6;
untainted_ok($^O);
BEGIN { delete @ENV{ qw( http_proxy HTTP_PROXY ) }; }
BEGIN {
use_ok( 'WWW::Mechanize::Pluggable' );
}
It would appear, the BEGIN was not seeing the 'plan' line so moving
that inside the BEGIN:
taint.t
t/taint......
1..6
ok 1 - use WWW::Mechanize::Pluggable;
ok 2
ok 3 - Created object isa WWW::Mechanize::Pluggable
ok 4 - ENV taints OK
ok 5 - Correct title
ok 6 - Title should not be tainted
ok 7 - But content should
# Looks like you planned 6 tests but ran 1 extra.
Ah, so change it to
BEGIN {
plan tests=>7;
use_ok( 'WWW::Mechanize::Pluggable' );
}
and I get:
ok 1 - use WWW::Mechanize::Pluggable;
ok 2
...
ok 6 - Title should not be tainted
ok 7 - But content should
ok
All tests successful.
Files=1, Tests=7, 1 wallclock secs ( 0.02 usr 0.01 sys + 0.82 cusr
0.08 csys = 0.93 CPU)
Result: PASS
Er, alright. '2' is empty - Ah, missed:
untainted_ok($^O);
So, if I add a descript to that, prove gives me 7 tests w/ desc and I
find 7 tests in the file. Now I see 8 'ok' lines but ...
a
Background - trying to be able to 'make smoke' for parrot on a
relatively new install of opensuse. It wasn't working via cpan, so,
what the heck, I installed perl 5.10. Went back and started w/
install Bundle::Test and ran into lots of missing reqs and after a day
or so, got it down to a few final messes (including needing to install
tidy/libtidy from cvs). One of which was WWW::Mechanize::Pluggable and
that seemed to be having issues w/ Test::Taint. Well, Test::Taint
wasn't installed, so I installed that and, from the cpan/build/W:B:P
dir found
...
t/taint......You tried to run a test without a plan at t/taint.t line 17.
Okay, this is part of where I don't quite get testing but taint.t has:
#!perl -T
use warnings;
use strict;
use Test::More;
use URI;
eval "use Test::Taint";
($^O) = ($^O =~ /.*/);
plan skip_all => "Test::Taint required for checking taintedness" if $@;
plan tests=>6;
untainted_ok($^O);
BEGIN { delete @ENV{ qw( http_proxy HTTP_PROXY ) }; }
BEGIN {
use_ok( 'WWW::Mechanize::Pluggable' );
}
It would appear, the BEGIN was not seeing the 'plan' line so moving
that inside the BEGIN:
taint.t
t/taint......
1..6
ok 1 - use WWW::Mechanize::Pluggable;
ok 2
ok 3 - Created object isa WWW::Mechanize::Pluggable
ok 4 - ENV taints OK
ok 5 - Correct title
ok 6 - Title should not be tainted
ok 7 - But content should
# Looks like you planned 6 tests but ran 1 extra.
Ah, so change it to
BEGIN {
plan tests=>7;
use_ok( 'WWW::Mechanize::Pluggable' );
}
and I get:
ok 1 - use WWW::Mechanize::Pluggable;
ok 2
...
ok 6 - Title should not be tainted
ok 7 - But content should
ok
All tests successful.
Files=1, Tests=7, 1 wallclock secs ( 0.02 usr 0.01 sys + 0.82 cusr
0.08 csys = 0.93 CPU)
Result: PASS
Er, alright. '2' is empty - Ah, missed:
untainted_ok($^O);
So, if I add a descript to that, prove gives me 7 tests w/ desc and I
find 7 tests in the file. Now I see 8 'ok' lines but ...
a
Re: Testing befuddlement
User:
chrisdolan
Date: 4/8/2008 12:45 am
Date: 4/8/2008 12:45 am
Views: 1
Rating: 0
Rating: 0
This is a common bug that was exposed by a recent cleanup in Test::More. ?As you said, the problem is the lines:
?? BEGIN {
?? ? ?use_ok( 'WWW::Mechanize::Pluggable' );
?? }
which happens at compile time, which is *before*
?? plan tests=>6;
which happens at run time. ?The easiest fix I've seen is to omit the "use_ok" and just do a normal "use" because if there's a syntax error in WWW::Mechanize::Pluggable, you probably want your test to crash anyway. ?IMO, use_ok and require_ok are often more trouble than they're worth.
The 8th OK is the summary OK for the whole test file, which (I think) comes from Test::Harness rather than your test program.
Chris
On Apr 7, 2008, at 3:56 PM, <afbach@gmail.com> <afbach@gmail.com> wrote:
afbach wrote:
Hey.
Background - trying to be able to 'make smoke' for parrot on a
relatively new install of opensuse. ?It wasn't working via cpan, so,
what the heck, I installed perl 5.10. ?Went back and started w/
install Bundle::Test and ran into lots of missing reqs and after a day
or so, got it down to a few final messes (including needing to install
tidy/libtidy from cvs). One of which was WWW::Mechanize::Pluggable and
that seemed to be having issues w/ Test::Taint. ? Well, Test::Taint
wasn't installed, so I installed that and, from the cpan/build/W:B:P
dir found
...
t/taint......You tried to run a test without a plan at t/taint.t line 17.
Okay, this is part of where I don't quite get testing but taint.t has:
#!perl -T
use warnings;
use strict;
use Test::More;
use URI;
eval "use Test::Taint";
($^O) = ($^O =~ /.*/);
plan skip_all => "Test::Taint required for checking taintedness" if $@;
plan tests=>6;
untainted_ok($^O);
BEGIN { delete @ENV{ qw( http_proxy HTTP_PROXY ) }; }
BEGIN {
? ?use_ok( 'WWW::Mechanize::Pluggable' );
}
It would appear, the BEGIN was not seeing the 'plan' line so moving
that inside the BEGIN:
taint.t
t/taint......
1..6
ok 1 - use WWW::Mechanize::Pluggable;
ok 2
ok 3 - Created object isa WWW::Mechanize::Pluggable
ok 4 - ENV taints OK
ok 5 - Correct title
ok 6 - Title should not be tainted
ok 7 - But content should
# Looks like you planned 6 tests but ran 1 extra.
Ah, so change it to
BEGIN {
plan tests=>7;
? ?use_ok( 'WWW::Mechanize::Pluggable' );
}
and I get:
ok 1 - use WWW::Mechanize::Pluggable;
ok 2
...
ok 6 - Title should not be tainted
ok 7 - But content should
ok
All tests successful.
Files=1, Tests=7, ?1 wallclock secs ( 0.02 usr ?0.01 sys + ?0.82 cusr
0.08 csys = ?0.93 CPU)
Result: PASS
Er, alright. ?'2' is empty - Ah, missed:
untainted_ok($^O);
So, if I add a descript to that, prove gives me 7 tests w/ desc and I
find 7 tests in the file. Now I see 8 'ok' lines but ...
a
Madison Area Perl Mongers - MadMongers



