Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Testing error handling that calls "die"

by TomDLux (Vicar)
on Dec 26, 2011 at 19:59 UTC ( #945127=note: print w/replies, xml ) Need Help??

in reply to Testing error handling that calls "die"

Ovid's 3-part article on Test::Class at the Modern Perl website taught me the basics of testing exceptions:

That should be pretty clear. Look at the new test now. Use the th +rows_ok test from Test::Exception to test the Carp::croak(). Using Test:: +Most instead of Test::More makes this test function available without +explicitly using Test::Exception. sub full_name : Tests(no_plan) { my $test = shift; my $person = $test->class->new; can_ok $person, 'full_name'; throws_ok { $person->full_name } qr/^Both first and last names must be set/, '... and full_name() should croak() if the either name is + not set';

Don't forget the first arg to throws_ok is a code block or anon subroutine

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://945127]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2018-06-19 14:42 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.