X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faggregate%2Funit_core_log_autoflush.t;fp=t%2Faggregate%2Funit_core_log_autoflush.t;h=530d47580a4ddb9c584acae221373e18c5416db4;hb=66ef16798266544a462bc6f0250cc693caec47ed;hp=0000000000000000000000000000000000000000;hpb=eb0d3cdea253b57559d190821a4f11b6265661ab;p=catagits%2FCatalyst-Runtime.git diff --git a/t/aggregate/unit_core_log_autoflush.t b/t/aggregate/unit_core_log_autoflush.t new file mode 100755 index 0000000..530d475 --- /dev/null +++ b/t/aggregate/unit_core_log_autoflush.t @@ -0,0 +1,66 @@ +use strict; +use warnings; + +use Test::More tests => 20; + +use Catalyst::Log; + +local *Catalyst::Log::_send_to_log; +local our @MESSAGES; +{ + no warnings 'redefine'; + *Catalyst::Log::_send_to_log = sub { + my $self = shift; + push @MESSAGES, @_; + }; +} + +my $LOG = 'Catalyst::Log'; + +can_ok $LOG, 'new'; +ok my $log = $LOG->new, '... and creating a new log object should succeed'; +isa_ok $log, $LOG, '... and the object it returns'; + +can_ok $log, 'is_info'; +ok $log->is_info, '... and the default behavior is to allow info messages'; + +can_ok $log, 'info'; +ok $log->info('hello there!'), + '... passing it an info message should succeed'; + +ok @MESSAGES, '... and immediately flush the log'; +is scalar @MESSAGES, 1, '... with one log message'; +like $MESSAGES[0], qr/^\[info\] hello there!$/, + '... which should match the format we expect'; + +{ + + package Catalyst::Log::Subclass; + use base qw/Catalyst::Log/; + + sub _send_to_log { + my $self = shift; + push @MESSAGES, '---'; + push @MESSAGES, @_; + } +} + +@MESSAGES = (); # clear the message log + +my $SUBCLASS = 'Catalyst::Log::Subclass'; +can_ok $SUBCLASS, 'new'; +ok $log = Catalyst::Log::Subclass->new, + '... and the log subclass constructor should return a new object'; +isa_ok $log, $SUBCLASS, '... and the object it returns'; +isa_ok $log, $LOG, '... and it also'; + +can_ok $log, 'info'; +ok $log->info('hi there!'), + '... passing it an info message should succeed'; + +ok @MESSAGES, '... and immediately flush the log'; +is scalar @MESSAGES, 2, '... with two log messages'; +is $MESSAGES[0], '---', '... with the first one being our new data'; +like $MESSAGES[1], qr/^\[info\] hi there!$/, + '... which should match the format we expect'; +