Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: testing a croak

by tirwhan (Abbot)
on Jan 19, 2006 at 06:39 UTC ( [id://524142]=note: print w/replies, xml ) Need Help??


in reply to testing a croak

You can use the Test::Exception module and test with either dies_ok(tests for death) or throws_ok (tests for death with a specific error message).

use Test::Exception => 1; throws_ok { dying_sub() } qr/I always die/, "sub dies with correct err +or message";

There are ten types of people: those that understand binary and those that don't.

Replies are listed 'Best First'.
Re^2: testing a croak
by arcnon (Monk) on Jan 19, 2006 at 13:44 UTC
    I tried test exception but it kills the script

    if I comment out this test

    All tests successful.

    Now with the test

    ... use_ok( 'Test::Exception' ); ... throws_ok { $objRef->parse_date_string() } qr/improper initialization +please see the docs/, 'checking 2 few args'; t/01-object....ok 1/23improper initialization please see the docs at t +/01-object.t line 56 # Looks like your test died just after 23. t/01-object....dubious + Test returned status 255 (wstat 65280, 0xff00) after all the subtests completed successfully Failed Test Stat Wstat Total Fail Failed List of Failed ------------------------------------------------------------ t/01-object.t 255 65280 23 0 0.00% ?? Failed 1/2 test scripts, 50.00% okay. 0/25 subtests failed, 100.00% ok +ay. make: *** [test_dynamic] Error 255

      If you load Test::Exception with use_ok you need to do so in a BEGIN block.

      BEGIN { use_ok('Test::Exception'}; }

      will work.


      There are ten types of people: those that understand binary and those that don't.
        I am doing that

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-24 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found