1Log::Any::Test(3) User Contributed Perl Documentation Log::Any::Test(3)
2
3
4
6 Log::Any::Test -- Test what you're logging with Log::Any
7
9 use Test::More;
10 use Log::Any::Test; # should appear before 'use Log::Any'!
11 use Log::Any qw($log);
12
13 # ...
14 # call something that logs using Log::Any
15 # ...
16
17 # now test to make sure you logged the right things
18
19 $log->contains_ok(qr/good log message/, "good message was logged");
20 $log->does_not_contain_ok(qr/unexpected log message/, "unexpected message was not logged");
21 $log->empty_ok("no more logs");
22
23 # or
24
25 my $msgs = $log->msgs;
26 cmp_deeply($msgs, [{message => 'msg1', level => 'debug'}, ...]);
27
29 "Log::Any::Test" is a simple module that allows you to test what has
30 been logged with Log::Any. Most of its API and implementation have been
31 taken from Log::Any::Dispatch.
32
33 Using "Log::Any::Test" sends all subsequent Log::Any log messages to a
34 single global in-memory buffer. It should be used before Log::Any.
35
37 The test_name is optional in the *_ok methods; a reasonable default
38 will be provided.
39
40 msgs ()
41 Returns the current contents of the global log buffer as an array
42 reference, where each element is a hash containing a category,
43 level, and message key. e.g.
44
45 {
46 category => 'Foo',
47 level => 'error',
48 message => 'this is an error'
49 },
50 {
51 category => 'Bar::Baz',
52 level => 'debug',
53 message => 'this is a debug'
54 }
55
56 contains_ok ($regex[, $test_name])
57 Tests that a message in the log buffer matches $regex. On success,
58 the message is removed from the log buffer (but any other matches
59 are left untouched).
60
61 does_not_contain_ok ($regex[, $test_name])
62 Tests that no message in the log buffer matches $regex.
63
64 empty_ok ([$test_name])
65 Tests that there is no log buffer left. On failure, the log buffer
66 is cleared to limit further cascading failures.
67
68 contains_only_ok ($regex[, $test_name])
69 Tests that there is a single message in the log buffer and it
70 matches $regex. On success, the message is removed.
71
72 clear ()
73 Clears the log buffer.
74
76 Log::Any, Test::Log::Dispatch
77
79 Jonathan Swartz
80
82 Copyright (C) 2009 Jonathan Swartz, all rights reserved.
83
84 This program is free software; you can redistribute it and/or modify it
85 under the same terms as Perl itself.
86
87
88
89perl v5.12.2 2009-12-08 Log::Any::Test(3)