From: Arthur Axel 'fREW' Schmidt Date: Sun, 14 Feb 2010 08:21:50 +0000 (-0600) Subject: real tests for logs X-Git-Tag: v0.00100~34 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c19d7beec540b8f5f25be84a73684fcccb81a04d;p=p5sagit%2FLog-Contextual.git real tests for logs --- diff --git a/t/lib/VarLogger.pm b/t/lib/VarLogger.pm new file mode 100644 index 0000000..0e1de89 --- /dev/null +++ b/t/lib/VarLogger.pm @@ -0,0 +1,8 @@ +package VarLogger; + +sub new { bless { var => undef }, __PACKAGE__ } +sub debug { $_[0]->{var} = $_[1] } +sub var { $_[0]->{var} } +sub is_debug { 1 } + +1; diff --git a/t/log.t b/t/log.t index 9bb5b29..56fad42 100644 --- a/t/log.t +++ b/t/log.t @@ -1,18 +1,45 @@ use strict; use warnings; +use lib 't/lib'; +use VarLogger; use Log::Contextual; use Test::More qw(no_plan); -my $logger = sub { WarnLogger->new }; +my $var_logger1 = VarLogger->new; +my $var_logger2 = VarLogger->new; +my $var_logger3 = VarLogger->new; -set_logger($logger); -log_debug { 'frew!' }; +WITHLOGGER: { + with_logger { + with_logger { + log_debug { 'nothing!' } + } sub { $var_logger1 }; + log_debug { 'frew!' }; + } sub { $var_logger2 }; -BEGIN { - package WarnLogger; - sub debug { warn $_[1] } - sub is_debug { 1 } - sub new { bless {}, __PACKAGE__ } + is( $var_logger1->var, 'nothing!', 'inner scoped logger works' ); + is( $var_logger2->var, 'frew!', 'outer scoped logger works' ); +} + +SETLOGGER: { + set_logger(sub { $var_logger3 }); + log_debug { 'set_logger' }; + is( $var_logger3->var, 'set_logger', 'set logger works' ); +} + +SETWITHLOGGER: { + with_logger { + log_debug { 'nothing again!' } + } sub { $var_logger1 }; + + is( $var_logger1->var, 'nothing again!', + 'inner scoped logger works after using set_logger' + ); + + log_debug { 'frioux!' }; + is( $var_logger3->var, 'frioux!', + q{set_logger's logger comes back after scoped logger} + ); }