Title: RE: capturing carp()s in module tests?

> i want to test error checks in a module i'm working on.  the
> error paths carp() the problem and then proceed.
>
> is there any way to capture the carp text (without using
> some of Carp.pm's internal routines) for testing that they're
> correct under the various error conditions?

Intercept $SIG{__WARN__} and $SIG{__DIE__} and youll capture all dies and warnings, including those generated by Carp. Unfortunately it isnt straightforward handling $SIG{__DIE__} correctly if eval is in use.

Or override Carp::carp().

Something like

*Carp::carp=sub {
   $message=Carp::shortmess @_;
   handle_carp_message($message);
   warn $message;
};


Yves



Reply via email to