Hi all,

I've been refactoring a bunch of old tests with Test::More and some
convenience routines for testing exceptions dropped out (along with some
class base testing and mock object modules which still need cleaning up into
something sane.)

    dies_ok BLOCK TEST_NAME
        Tests to see that BLOCK exits by dying, rather than by exiting
        normally. For example:
    
            dies_ok { div(1, 0) } 'divide by zero detected';
    
    lives_ok BLOCK TEST_NAME
        Tests to see that BLOCK exits normally, and doesn't die. For
        example:

            lives_ok { $file = read_file('test.txt') } 'file read';
    
    throws_ok BLOCK REGEX, TEST_NAME
    throws_ok BLOCK CLASS, TEST_NAME
        Tests to see that BLOCK throws a specific exception.

        In the first form the test passes if the stringified exception
        matches the give regular expression. For example:

            throws_ok {
                read_file('test.txt')
            } qr/No such file/, 'no file';

        In the second form the test passes if the exception is of the same
        class as the one supplied, or a subclass of that class. For example:

            throws_ok {$foo->bar} "Error::Simple", 'simple error';

(you can find the code at
<http://www.quietstars.com/perl/Test-Exception-0.02.tar.gz> if you want to
play)
        
Any comments before I throw it at CPAN? Sound vaguely sane?

Cheers,

Adrian

Reply via email to