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