1Test::Log::Dispatch(3)User Contributed Perl DocumentationTest::Log::Dispatch(3)
2
3
4

NAME

6       Test::Log::Dispatch -- Test what you are logging
7

SYNOPSIS

9           use Test::More;
10           use Test::Log::Dispatch;
11
12           my $log = Test::Log::Dispatch->new();
13
14           # ...
15           # call something that logs to $log
16           # ...
17
18           # now test to make sure you logged the right things
19
20           $log->contains_ok(qr/good log message/, "good message was logged");
21           $log->does_not_contain_ok(qr/unexpected log message/, "unexpected message was not logged");
22           $log->empty_ok("no more logs");
23
24           # or
25
26           my $msgs = $log->msgs;
27           cmp_deeply($msgs, ['msg1', 'msg2', 'msg3']);
28

DESCRIPTION

30       "Test::Log::Dispatch" is a "Log::Dispatch" object that keeps track of
31       everything logged to it in memory, and provides convenient tests
32       against what has been logged.
33

CONSTRUCTOR

35       The constructor returns a "Test::Log::Dispatch" object, which inherits
36       from "Log::Dispatch" and contains a single "Log::Dispatch::Array"
37       output at 'debug' level.
38
39       The constructor requires no parameters. Any parameters will be
40       forwarded to the "Log::Dispatch::Array" constructor. For example, you
41       can pass a min_level to override the default 'debug'.
42

METHODS

44       The test_name is optional in the *_ok methods; a reasonable default
45       will be provided.
46
47       contains_ok ($regex[, $test_name])
48           Tests that a message in the log buffer matches $regex. On success,
49           the message is removed from the log buffer (but any other matches
50           are left untouched).
51
52       does_not_contain_ok ($regex[, $test_name])
53           Tests that no message in the log buffer matches $regex.
54
55       empty_ok ([$test_name])
56           Tests that there is no log buffer left. On failure, the log buffer
57           is cleared to limit further cascading failures.
58
59       contains_only_ok ($regex[, $test_name])
60           Tests that there is a single message in the log buffer and it
61           matches $regex. On success, the message is removed.
62
63       clear ()
64           Clears the log buffer.
65
66       msgs ()
67           Returns the current contents of the log buffer as an array
68           reference, where each element is a hash containing a message and
69           level key.
70

TO DO

72       ยท   Allow testing of log levels.
73

SEE ALSO

75       Log::Dispatch, Test::Log4perl
76

AUTHOR

78       Jonathan Swartz
79
81       Copyright (C) 2009 Jonathan Swartz, all rights reserved.
82
83       This program is free software; you can redistribute it and/or modify it
84       under the same terms as Perl itself.
85
86
87
88perl v5.32.0                      2020-07-28            Test::Log::Dispatch(3)
Impressum