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