On Wed, Dec 03, 2003 at 10:20:03AM +0000, Fergal Daly wrote:
> On Tue, Dec 02, 2003 at 10:05:46PM -0800, Michael G Schwern wrote:
> > Why not?
> > 
> >     catch MyError with {
> >             like( $ex, qr/Bad thing/ );
> >     };
> 
> If there is no exception then then that test won't execute. It'd have to be
> something like
> 
> try {
>       f();
>       fail("no exception");
> }
> catch MyError with {
>       like( $ex, qr/Bad thing/ );
> };
> 
> but that runs the risk of forgetting the fail(),

Ahh.  Then I'd suggest something like this.

        catch_like { f(); } 'MyError', qr/Bad thing/;

Where catch_like is something like:

        my $TB = Test::Builder->new;
        sub catch_like {
                my($sub, $exception, $regex) = @_;

                try {
                        $sub->();
                };
                $exception->catch(with { $TB->like( shift, $regex ) }); 
        }


-- 
Michael G Schwern        [EMAIL PROTECTED]  http://www.pobox.com/~schwern/
1. You are thin.
2. You look great.
3. You live in a castle with robot servants.
        -- http://www.angryflower.com/anaddi.gif

Reply via email to