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