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