From: Arthur Axel 'fREW' Schmidt Date: Sun, 21 Feb 2010 04:01:02 +0000 (-0600) Subject: tests for empty lists passed to Dlog X-Git-Tag: v0.00100~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=db70b0a5c2d21c1e60f1149b93407772e8939926;p=p5sagit%2FLog-Contextual.git tests for empty lists passed to Dlog --- diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index 35a7667..bd691e3 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -182,7 +182,11 @@ sub Dlog_trace (&@) { my $code = shift; my @values = @_; return log_trace { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + if (@values) { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + } else { + do { local $_ = '()'; $code->() }; + } } @values } @@ -190,7 +194,11 @@ sub Dlog_debug (&@) { my $code = shift; my @values = @_; log_debug { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + if (@values) { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + } else { + do { local $_ = '()'; $code->() }; + } } @values } @@ -198,7 +206,11 @@ sub Dlog_info (&@) { my $code = shift; my @values = @_; log_info { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + if (@values) { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + } else { + do { local $_ = '()'; $code->() }; + } } @values } @@ -206,7 +218,11 @@ sub Dlog_warn (&@) { my $code = shift; my @values = @_; log_warn { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + if (@values) { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + } else { + do { local $_ = '()'; $code->() }; + } } @values } @@ -214,7 +230,11 @@ sub Dlog_error (&@) { my $code = shift; my @values = @_; log_error { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + if (@values) { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + } else { + do { local $_ = '()'; $code->() }; + } } @values } @@ -222,7 +242,11 @@ sub Dlog_fatal (&@) { my $code = shift; my @values = @_; log_fatal { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + if (@values) { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + } else { + do { local $_ = '()'; $code->() }; + } } @values } diff --git a/t/dlog.t b/t/dlog.t index 2d4f118..49b1c2b 100644 --- a/t/dlog.t +++ b/t/dlog.t @@ -132,3 +132,42 @@ fLook ma, data: [ ] OUT } + + + +{ + my @foo = Dlog_trace { "nothing: $_" } (); + ok( eq_array(\@foo, []), 'Dlog_trace passes nothing through correctly'); + is( $var_log->var, 'tnothing: ()', 'Output for Dlog_trace is correct'); +} + +{ + my @foo = Dlog_debug { "nothing: $_" } (); + ok( eq_array(\@foo, []), 'Dlog_debug passes nothing through correctly'); + is( $var_log->var, 'dnothing: ()', 'Output for Dlog_debug is correct'); +} + +{ + my @foo = Dlog_info { "nothing: $_" } (); + ok( eq_array(\@foo, []), 'Dlog_info passes nothing through correctly'); + is( $var_log->var, 'inothing: ()', 'Output for Dlog_info is correct'); +} + +{ + my @foo = Dlog_warn { "nothing: $_" } (); + ok( eq_array(\@foo, []), 'Dlog_warn passes nothing through correctly'); + is( $var_log->var, 'wnothing: ()', 'Output for Dlog_warn is correct'); +} + +{ + my @foo = Dlog_error { "nothing: $_" } (); + ok( eq_array(\@foo, []), 'Dlog_error passes nothing through correctly'); + is( $var_log->var, 'enothing: ()', 'Output for Dlog_error is correct'); +} + +{ + my @foo = Dlog_fatal { "nothing: $_" } (); + ok( eq_array(\@foo, []), 'Dlog_fatal passes nothing through correctly'); + is( $var_log->var, 'fnothing: ()', 'Output for Dlog_fatal is correct'); +} +