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 version 1.708
10
12 use Test::More;
13 use Log::Any::Test; # should appear before 'use Log::Any'!
14 use Log::Any qw($log);
15
16 # ...
17 # call something that logs using Log::Any
18 # ...
19
20 # now test to make sure you logged the right things
21
22 $log->contains_ok(qr/good log message/, "good message was logged");
23 $log->does_not_contain_ok(qr/unexpected log message/, "unexpected message was not logged");
24 $log->empty_ok("no more logs");
25
26 # or
27
28 my $msgs = $log->msgs;
29 cmp_deeply($msgs, [{message => 'msg1', level => 'debug'}, ...]);
30
32 "Log::Any::Test" is a simple module that allows you to test what has
33 been logged with Log::Any. Most of its API and implementation have been
34 taken from Log::Any::Dispatch.
35
36 Using "Log::Any::Test" signals "Log::Any" to send all subsequent log
37 messages to a single global in-memory buffer and to make the log proxy
38 provide a number of testing functions. To use it, load
39 "Log::Any::Test" before anything that loads "Log::Any". To actually
40 use the test methods, you need to load "Log::Any" and get a log object
41 from it, as shown in the "SYNOPSIS".
42
44 The test_name is optional in the *_ok methods; a reasonable default
45 will be provided.
46
47 msgs ()
48 Returns the current contents of the global log buffer as an array
49 reference, where each element is a hash containing a category,
50 level, and message key. e.g.
51
52 {
53 category => 'Foo',
54 level => 'error',
55 message => 'this is an error'
56 },
57 {
58 category => 'Bar::Baz',
59 level => 'debug',
60 message => 'this is a debug'
61 }
62
63 contains_ok ($regex[, $test_name])
64 Tests that a message in the log buffer matches $regex. On success,
65 the message is removed from the log buffer (but any other matches
66 are left untouched).
67
68 does_not_contain_ok ($regex[, $test_name])
69 Tests that no message in the log buffer matches $regex.
70
71 category_contains_ok ($category, $regex[, $test_name])
72 Tests that a message in the log buffer from a specific category
73 matches $regex. On success, the message is removed from the log
74 buffer (but any other matches are left untouched).
75
76 category_does_not_contain_ok ($category, $regex[, $test_name])
77 Tests that no message from a specific category in the log buffer
78 matches $regex.
79
80 empty_ok ([$test_name])
81 Tests that there is no log buffer left. On failure, the log buffer
82 is cleared to limit further cascading failures.
83
84 contains_only_ok ($regex[, $test_name])
85 Tests that there is a single message in the log buffer and it
86 matches $regex. On success, the message is removed.
87
88 clear ()
89 Clears the log buffer.
90
92 Log::Any, Test::Log::Dispatch
93
95 • Jonathan Swartz <swartz@pobox.com>
96
97 • David Golden <dagolden@cpan.org>
98
99 • Doug Bell <preaction@cpan.org>
100
101 • Daniel Pittman <daniel@rimspace.net>
102
103 • Stephen Thirlwall <sdt@cpan.org>
104
106 This software is copyright (c) 2017 by Jonathan Swartz, David Golden,
107 and Doug Bell.
108
109 This is free software; you can redistribute it and/or modify it under
110 the same terms as the Perl 5 programming language system itself.
111
112
113
114perl v5.32.1 2021-01-27 Log::Any::Test(3)