From: Arthur Axel 'fREW' Schmidt Date: Sat, 20 Feb 2010 22:51:00 +0000 (-0600) Subject: tests for SimpleLogger X-Git-Tag: v0.00100~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aea780aa2b78f3cc38dd57d0c4a6488524e20906;p=p5sagit%2FLog-Contextual.git tests for SimpleLogger --- diff --git a/t/simplelogger.t b/t/simplelogger.t index 87ae8ca..05e6f53 100644 --- a/t/simplelogger.t +++ b/t/simplelogger.t @@ -20,3 +20,31 @@ ok(eval { log_info { die 'this should live' }; 1}, 'info does not get called'); ok(eval { log_warn { die 'this should live' }; 1}, 'warn does not get called'); ok(eval { log_error { die 'this should live' }; 1}, 'error does not get called'); ok(eval { log_fatal { die 'this should live' }; 1}, 'fatal does not get called'); + +{ + my $cap; + local *STDERR = do { open my $fh, '>', \$cap; $fh }; + + log_debug { 'frew' }; + is($cap, "[debug] frew\n", 'SimpleLogger outputs to STDERR correctly'); +} + +my $response; +my $l2 = Log::Contextual::SimpleLogger->new({ + levels => [qw{trace debug info warn error fatal}], + coderef => sub { $response = $_[0] }, +}); +set_logger($l2); +log_trace { 'trace' }; +is($response, "[trace] trace\n", 'trace renders correctly'); +log_debug { 'debug' }; +is($response, "[debug] debug\n", 'debug renders correctly'); +log_info { 'info' }; +is($response, "[info] info\n", 'info renders correctly'); +log_warn { 'warn' }; +is($response, "[warn] warn\n", 'warn renders correctly'); +log_error { 'error' }; +is($response, "[error] error\n", 'error renders correctly'); +log_fatal { 'fatal' }; +is($response, "[fatal] fatal\n", 'fatal renders correctly'); +