| 1 |
NAME |
| 2 |
Test::Log::Dispatch -- Test what you are logging |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use Test::More; |
| 6 |
use Test::Log::Dispatch; |
| 7 |
|
| 8 |
my $log = Test::Log::Dispatch->new(); |
| 9 |
|
| 10 |
# ... |
| 11 |
# call something that logs to $log |
| 12 |
# ... |
| 13 |
|
| 14 |
# now test to make sure you logged the right things |
| 15 |
|
| 16 |
$log->contains_ok(qr/good log message/, "good message was logged"); |
| 17 |
$log->does_not_contain_ok(qr/unexpected log message/, "unexpected message was not logged"); |
| 18 |
$log->empty_ok("no more logs"); |
| 19 |
|
| 20 |
# or |
| 21 |
|
| 22 |
my $msgs = $log->msgs; |
| 23 |
cmp_deeply($msgs, ['msg1', 'msg2', 'msg3']); |
| 24 |
|
| 25 |
DESCRIPTION |
| 26 |
`Test::Log::Dispatch' is a `Log::Dispatch' object that keeps track of |
| 27 |
everything logged to it in memory, and provides convenient tests against |
| 28 |
what has been logged. |
| 29 |
|
| 30 |
CONSTRUCTOR |
| 31 |
The constructor returns a `Test::Log::Dispatch' object, which inherits |
| 32 |
from `Log::Dispatch' and contains a single `Log::Dispatch::Array' output |
| 33 |
at 'debug' level. |
| 34 |
|
| 35 |
The constructor requires no parameters. Any parameters will be forwarded |
| 36 |
to the `Log::Dispatch::Array' constructor. For example, you can pass a |
| 37 |
*min_level* to override the default 'debug'. |
| 38 |
|
| 39 |
METHODS |
| 40 |
The test_name is optional in the *_ok methods; a reasonable default will |
| 41 |
be provided. |
| 42 |
|
| 43 |
contains_ok ($regex[, $test_name]) |
| 44 |
Tests that a message in the log buffer matches *$regex*. On success, |
| 45 |
the message is *removed* from the log buffer (but any other matches |
| 46 |
are left untouched). |
| 47 |
|
| 48 |
does_not_contain_ok ($regex[, $test_name]) |
| 49 |
Tests that no message in the log buffer matches *$regex*. |
| 50 |
|
| 51 |
empty_ok ([$test_name]) |
| 52 |
Tests that there is no log buffer left. On failure, the log buffer |
| 53 |
is cleared to limit further cascading failures. |
| 54 |
|
| 55 |
contains_only_ok ($regex[, $test_name]) |
| 56 |
Tests that there is a single message in the log buffer and it |
| 57 |
matches *$regex*. On success, the message is removed. |
| 58 |
|
| 59 |
clear () |
| 60 |
Clears the log buffer. |
| 61 |
|
| 62 |
msgs () |
| 63 |
Returns the current contents of the log buffer as an array |
| 64 |
reference, where each element is a hash containing a *message* and |
| 65 |
*level* key. |
| 66 |
|
| 67 |
TO DO |
| 68 |
* Allow testing of log levels. |
| 69 |
|
| 70 |
SEE ALSO |
| 71 |
Log::Dispatch, Test::Log4perl |
| 72 |
|
| 73 |
AUTHOR |
| 74 |
Jonathan Swartz |
| 75 |
|
| 76 |
COPYRIGHT & LICENSE |
| 77 |
Copyright (C) 2009 Jonathan Swartz, all rights reserved. |
| 78 |
|
| 79 |
This program is free software; you can redistribute it and/or modify it |
| 80 |
under the same terms as Perl itself. |
| 81 |
|