Skip to content

CPAN Smoke Testing: An unsung hero

January 23, 2009
tags: ,

One of the great things about CPAN is that it runs automated smoke testing on all modules uploaded to it.

I recently implemented a small feature in my Builder module and CPAN currently informs me that my test suite as passed 63 times, failed on 7 occasasions and returned an unknown status 3 times. Here’s the current breakdown of the smoke testing matrix of these different versions of Perl & OS’es the Bulder test suite as been run on.

http://www.cpantesters.org/show/Builder.html#Builder-0.02

NB. you will probably need to select 0.02 now that I’ve uploaded new versions of Builder

From this I can see that there is a problem with one of my tests when running on Perl 5.6.*…..

http://www.nntp.perl.org/group/perl.cpan.testers/2009/01/msg2976740.html

The culprit was this bit of code in my builder_xml_output.t test…

  my $got;
  open my $fh, '>', \$got or die $!; 

That second line creates a filehandle $fh which writes to an in memory file held in the scalar $got.
This allows me to capture output like STDOUT and perform tests on it.

After a bit of Googling I found that this feature was introduced with PerlIO which came with Perl 5.8. So hence test failure on Perl 5.6 ;-(

Solutions? Well I could just make sure only Perl 5.8 is used by placing the following at the top of my modules…

    use 5.008;

But hey that isn’t very community spirited of me ;-( And anyway there’s nothing in the Builder code that stops it working on
Perl 5.6 its just that “in memory” test line that 5.6 doesn’t like.

OK then I could just skip the tests on Perl 5.6 by amending my builder_xml_output.t like so….

    use Test::More;
    
    if ( $[ < 5.008 ) {
        plan skip_all => 'Cannot test before Perl 5.8';
    }
    else {
        plan tests => 2;
    }

Seems painless enough. But it does feel like i’m sweeping the problem under the carpet a little bit!

So after a bit more Googling I found a couple of better solutions but plumped for IO::Scalar (part of IO::Stringy). I downloaded the IO::Stringy source code folder straight from CPAN and into Builder’s test directory under “lib” and amended my builder_xml_output.t file like so…

    use Test::More tests => 2;
    use Builder;

    # local test library
    use lib 't/lib';
    use IO::Scalar;

    my $got;  
    my $fh = IO::Scalar->new( \$got ); 

    .... tests as before ....

Now test works on Perl 5.6 and above. Job done!

/I3az/

References:

Advertisement
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: