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