Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Test::NoWarnings test 'no warnings' apparently inconsistant

by mandog (Curate)
on Jun 01, 2008 at 22:21 UTC ( [id://689602]=perlquestion: print w/replies, xml ) Need Help??

mandog has asked for the wisdom of the Perl Monks concerning the following question:

I'm playing with  Test::NoWarnings.

When I test a sub from a module, that spits out warnings, Test::NoWarnings does not complain.

When I test a sub defined in the test file, test: 'no warnings' fails as i would expect.

What am I missing ?

See example code below

#!/usr/bin/perl -T # v5.8.8 (debian etch / ubuntu hardy) use Test::More tests=>2; # $VERSION .082 (ubuntu hardy) # $VERSION eq .084 (cpan) use Test::NoWarnings; use warnings; use strict; use lib qw| . |; use foo; # defined in foo.pm identical to get_match2 # does # is(get_match(undef),undef,'undef gives undef'); # defined below, test 'no warnings' fails as I expect is(get_match2(undef),undef,' match 2 undef gives undef'); sub get_match2 { my $match_me=shift; if ($match_me=~/(\d.+)/){ return $1; } else{ return undef; } }

Contents of foo.pm

Package foo; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( get_match ); sub get_match { my $match_me=shift; # if ($match_me=~/(.+)/){ return $1; } else{ return undef; } } 1;

Replies are listed 'Best First'.
Re: Test::NoWarnings test 'no warnings' apparently inconsistant
by pc88mxer (Vicar) on Jun 01, 2008 at 23:16 UTC
    It's not Test::NoWarnings fault. You'll get the warning if you use warnings in the file foo.pm.

      As noted you don't set warnings in your .pm, adding $^W++ in your .t test file will switch warnings on globally and thus make it behave as you desire.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://689602]
Approved by pc88mxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-23 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found