in reply to Re: testing a croak
in thread testing a croak

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

Replies are listed 'Best First'.
Re^3: testing a croak
by tirwhan (Abbot) on Jan 19, 2006 at 14:38 UTC

    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

        Hmm, that's odd, can you post a cut-down (but complete) version of your code which shows this problem. I.e. a complete runnable test script with only the one test and the code it calls which dies? Something like this:

        use Test::More tests => 2; BEGIN { use_ok("Test::Exception"); } sub slayme { die "Error message"; } throws_ok { slayme() } qr/Error message/,"Dies correctly"; __OUTPUT__ 1..2 ok 1 - use Test::Exception; ok 2 - Dies correctly

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