Authentication back compat fail due to ::ClassData not behaving like C::D::I, not...
[catagits/Catalyst-Runtime.git] / t / unit_core_log.t
CommitLineData
adee716c 1use strict;
2use warnings;
3
2c4bd922 4use Test::More tests => 23;
adee716c 5
adee716c 6my $LOG;
7
8BEGIN {
9 chdir 't' if -d 't';
10 use lib '../lib';
11 $LOG = 'Catalyst::Log';
12 use_ok $LOG or die;
13}
14my @MESSAGES;
15{
16 no warnings 'redefine';
17 *Catalyst::Log::_send_to_log = sub {
18 my $self = shift;
19 push @MESSAGES, @_;
20 };
21}
22
23can_ok $LOG, 'new';
24ok my $log = $LOG->new, '... and creating a new log object should succeed';
25isa_ok $log, $LOG, '... and the object it returns';
26
27can_ok $log, 'is_info';
28ok $log->is_info, '... and the default behavior is to allow info messages';
29
30can_ok $log, 'info';
31ok $log->info('hello there!'),
32 '... passing it an info message should succeed';
33
34can_ok $log, "_flush";
35$log->_flush;
36ok @MESSAGES, '... and flushing the log should succeed';
37is scalar @MESSAGES, 1, '... with one log message';
34d28dfd 38like $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
53my $SUBCLASS = 'Catalyst::Log::Subclass';
54can_ok $SUBCLASS, 'new';
55ok $log = Catalyst::Log::Subclass->new,
56 '... and the log subclass constructor shoudl return a new object';
57isa_ok $log, $SUBCLASS, '... and the object it returns';
58isa_ok $log, $LOG, '... and it also';
59
60can_ok $log, 'info';
61ok $log->info('hi there!'),
62 '... passing it an info message should succeed';
63
64can_ok $log, "_flush";
65@MESSAGES = (); # clear the message log
66$log->_flush;
67ok @MESSAGES, '... and flushing the log should succeed';
68is scalar @MESSAGES, 2, '... with two log messages';
69is $MESSAGES[0], '---', '... with the first one being our new data';
34d28dfd 70like $MESSAGES[1], qr/^\[info\] hi there!$/,
adee716c 71 '... which should match the format we expect';
72