Commit | Line | Data |
adee716c |
1 | use strict; |
2 | use warnings; |
3 | |
b1ead5a2 |
4 | use Test::More tests => 22; |
adee716c |
5 | |
5d50f369 |
6 | use Catalyst::Log; |
7 | |
8 | local *Catalyst::Log::_send_to_log; |
06400669 |
9 | local our @MESSAGES; |
adee716c |
10 | { |
11 | no warnings 'redefine'; |
12 | *Catalyst::Log::_send_to_log = sub { |
13 | my $self = shift; |
14 | push @MESSAGES, @_; |
15 | }; |
16 | } |
17 | |
5d50f369 |
18 | my $LOG = 'Catalyst::Log'; |
19 | |
adee716c |
20 | can_ok $LOG, 'new'; |
21 | ok my $log = $LOG->new, '... and creating a new log object should succeed'; |
22 | isa_ok $log, $LOG, '... and the object it returns'; |
23 | |
24 | can_ok $log, 'is_info'; |
25 | ok $log->is_info, '... and the default behavior is to allow info messages'; |
26 | |
27 | can_ok $log, 'info'; |
28 | ok $log->info('hello there!'), |
29 | '... passing it an info message should succeed'; |
30 | |
31 | can_ok $log, "_flush"; |
32 | $log->_flush; |
33 | ok @MESSAGES, '... and flushing the log should succeed'; |
34 | is scalar @MESSAGES, 1, '... with one log message'; |
34d28dfd |
35 | like $MESSAGES[0], qr/^\[info\] hello there!$/, |
adee716c |
36 | '... which should match the format we expect'; |
37 | |
38 | { |
39 | |
40 | package Catalyst::Log::Subclass; |
5e3aaea8 |
41 | use base qw/Catalyst::Log/; |
adee716c |
42 | |
43 | sub _send_to_log { |
44 | my $self = shift; |
45 | push @MESSAGES, '---'; |
46 | push @MESSAGES, @_; |
47 | } |
48 | } |
49 | |
50 | my $SUBCLASS = 'Catalyst::Log::Subclass'; |
51 | can_ok $SUBCLASS, 'new'; |
52 | ok $log = Catalyst::Log::Subclass->new, |
53 | '... and the log subclass constructor shoudl return a new object'; |
54 | isa_ok $log, $SUBCLASS, '... and the object it returns'; |
55 | isa_ok $log, $LOG, '... and it also'; |
56 | |
57 | can_ok $log, 'info'; |
58 | ok $log->info('hi there!'), |
59 | '... passing it an info message should succeed'; |
60 | |
61 | can_ok $log, "_flush"; |
62 | @MESSAGES = (); # clear the message log |
63 | $log->_flush; |
64 | ok @MESSAGES, '... and flushing the log should succeed'; |
65 | is scalar @MESSAGES, 2, '... with two log messages'; |
66 | is $MESSAGES[0], '---', '... with the first one being our new data'; |
34d28dfd |
67 | like $MESSAGES[1], qr/^\[info\] hi there!$/, |
adee716c |
68 | '... which should match the format we expect'; |
69 | |