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

Re: Test::More usage to test functions that die

by stvn (Monsignor)
on Dec 08, 2004 at 15:31 UTC ( #413229=note: print w/replies, xml ) Need Help??

in reply to Test::More usage to test functions that die

If you don't want to use Test::Exception (which I highly recommend), then the easist Test::More way of doing this would be this:

eval { $a->f1( ) }; ok($@, '... an exception has been thrown'); like($@, qr/\- parameter1 required/, '... and it is the correct except +ion');
I would also recomment when you test the function with parameters, to also wrap it inside an eval, like this:
eval { $a->f1("paramter" ) }; ok(!$@, '... no exception has been thrown');
This is the idea behind the lives_ok function in Test::Exception.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://413229]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2022-01-24 21:14 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (65 votes). Check out past polls.