Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-02-19 00:34 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (257 votes). Check out past polls.