From: Arthur Axel 'fREW' Schmidt Date: Wed, 3 Mar 2010 02:59:48 +0000 (-0600) Subject: test set_logger warning X-Git-Tag: v0.00200~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3e3680ac2dadf33a4dfb4f4142c4edc2a4c4ee89;p=p5sagit%2FLog-Contextual.git test set_logger warning --- diff --git a/t/log.t b/t/log.t index a833369..3a56c77 100644 --- a/t/log.t +++ b/t/log.t @@ -22,6 +22,22 @@ my $var_logger3 = Log::Contextual::SimpleLogger->new({ coderef => sub { $var3 = shift }, }); +SETLOGGER: { + set_logger(sub { $var_logger3 }); + log_debug { 'set_logger' }; + is( $var3, "[debug] set_logger\n", 'set logger works' ); +} + +SETLOGGERTWICE: { + my $foo; + local $SIG{__WARN__} = sub { $foo = shift }; + set_logger(sub { $var_logger3 }); + like( + $foo, qr/set_logger \(or -logger\) called more than once! This is a bad idea! at/, + 'set_logger twice warns correctly' + ); +} + WITHLOGGER: { with_logger sub { $var_logger2 } => sub { @@ -36,15 +52,11 @@ WITHLOGGER: { is( $var2, "[debug] frew!\n", 'outer scoped logger works' ); } -SETLOGGER: { - set_logger(sub { $var_logger3 }); - log_debug { 'set_logger' }; - is( $var3, "[debug] set_logger\n", 'set logger works' ); -} - SETWITHLOGGER: { with_logger $var_logger1 => sub { log_debug { 'nothing again!' }; + # do this just so the following set_logger won't warn + local $SIG{__WARN__} = sub {}; set_logger(sub { $var_logger3 }); log_debug { 'this is a set inside a with' }; };