It's so worthwhile that it's already there
http://search.cpan.org/~bigj/Test-Warn/
F
On Thu, Nov 20, 2003 at 02:27:48AM -0700, Jim Cromie wrote:
> hi all,
>
> im patching a module that uses Test::More, and I want to include a test
> to prove that a carp is being called when function args are wrong.
>
> I half-expected to find a stderr_like() that would do the trick.
>
> I ended up with this;
>
> {
> local $SIG{__WARN__} = sub {
> return if $_[0] =~ /following args are not recognized/;
> warn $_[0];
> };
> like ( $proxy = HTTP::Proxy->new( junk => 'not allowed' ),
> qr/HTTP::Proxy/, "ok");
> }
>
>
> which works to an extent, but isnt very clean, and appears to rely on
> Test::More
> watching STDERR to detect problems, and an obtuse suppression of the
> expected err.
>
> This module also uses STDERR for its own purposes (by default),
> that fact hasnt broken the above, but might be a confounding issue for
> a general solution.
>
>
> Is such a function a worthwhile addition to any of Test::* ?
>
> tia.
>