in reply to Re: Test::More : I'd need a "not_ok()" function...
in thread Test::More : I'd need a "not_ok()" function...

That's exactly what's happening to me! my_sub('bad') actually dies, that's my problem... a not_ok() would allow less cluttered test scripts than  eval {...}; is($@, 'something', 'test');
I dare trying using a good ol' ugly prototype :
sub not_ok(&$) { my $coderef = shift; my $message = shift; eval $coderef; ok( $@, $message) } # call this way not_ok( sub { mysub('bad data') }, 'message')
How do you find this? Not refined, but works.

Replies are listed 'Best First'.
Re^3: Test::More : I'd need a "not_ok()" function...
by Perl Mouse (Chaplain) on Oct 14, 2005 at 15:25 UTC
    I wouldn't call it 'not_ok', as that suggests 'ok !'. You want to test it dying, so I'd call it something like: 'die_cmp' (for exact testing of the die message) or 'die_like' (for regex testing of the die message).
    Perl --((8:>*
Re^3: Test::More : I'd need a "not_ok()" function...
by philcrow (Priest) on Oct 14, 2005 at 16:01 UTC
    I'm no expert on the internals of Test::More, but your method looks fine to me. I would follow the previous suggestion and call it die_ok or something similar. The maintainers usually have good opinions about the names.

    Phil

Re^3: Test::More : I'd need a "not_ok()" function...
by bluto (Curate) on Oct 14, 2005 at 16:12 UTC
    The main problem with this is that the routine you are testing *must* die. You can't use it for tests that just return 0 for failure (i.e. the opposite of what "ok()" does). Perhaps it should be named something like "should_die"?

    Also, you may want to use 'like()' instead of 'ok()' if you are matching a die message that contains dynamic information (e.g. filename, line number, stack trace, etc).