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

Re: Silencing warnings when testing

by Ovid (Cardinal)
on Oct 28, 2002 at 02:07 UTC ( #208432=note: print w/replies, xml ) Need Help??

in reply to Silencing warnings when testing

I typically use typeglobs to override the sub and capture the arguments. Then, you can test whether or not carp was called and if it received the correct arguments. Below is a test script.

#!/usr/bin/perl -w use strict; package Foo; use Carp; sub bar { carp "This is a test"; } package main; use Test::More 'no_plan'; use constant MODULE => 'Foo'; { my $carp; local *Foo::carp = sub { $carp = join '', @_ }; can_ok( MODULE, 'bar' ); Foo::bar(); ok( $carp, 'Calling Foo::bar() should call carp()' ); is( $carp, 'This is a test', '... with the correct error message' ); }

Just make sure that you localize the typeglob. This ensures that subsequent calls to carp that you forgot to trap will still spit out error messages.


Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://208432]
[yash1337]: kl

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2017-04-30 19:36 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (542 votes). Check out past polls.