From: Arthur Axel 'fREW' Schmidt Date: Sat, 20 Feb 2010 08:52:25 +0000 (-0600) Subject: tests for Core X-Git-Tag: v0.00100~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0f7a70e763aaa0ff93a89d63df33b6eae3f4522e;p=p5sagit%2FLog-Contextual.git tests for Core --- diff --git a/t/dlog.t b/t/dlog.t index 177d21f..1fd6586 100644 --- a/t/dlog.t +++ b/t/dlog.t @@ -8,8 +8,27 @@ use Test::More 'no_plan'; use Log::Contextual qw{:dlog set_logger}; my $var_log = VarLogger->new; +set_logger($var_log); + +my @foo = Dlog_trace { "Look ma, data: $_" } qw{frew bar baz}; +ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_trace passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for Dlog_trace is correct'); +tLook ma, data: "frew" +"bar" +"baz" +OUT + +my $bar = DlogS_trace { "Look ma, data: $_" } [qw{frew bar baz}]; +ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_trace passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for DlogS_trace is correct'); +tLook ma, data: [ + "frew", + "bar", + "baz" +] +OUT + -set_logger(sub { $var_log }); my @foo = Dlog_debug { "Look ma, data: $_" } qw{frew bar baz}; ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_debug passes data through correctly'); is( $var_log->var, <<'OUT', 'Output for Dlog_debug is correct'); @@ -17,6 +36,7 @@ dLook ma, data: "frew" "bar" "baz" OUT + my $bar = DlogS_debug { "Look ma, data: $_" } [qw{frew bar baz}]; ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_debug passes data through correctly'); is( $var_log->var, <<'OUT', 'Output for DlogS_debug is correct'); @@ -27,3 +47,79 @@ dLook ma, data: [ ] OUT + +my @foo = Dlog_info { "Look ma, data: $_" } qw{frew bar baz}; +ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_info passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for Dlog_info is correct'); +iLook ma, data: "frew" +"bar" +"baz" +OUT + +my $bar = DlogS_info { "Look ma, data: $_" } [qw{frew bar baz}]; +ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_info passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for DlogS_info is correct'); +iLook ma, data: [ + "frew", + "bar", + "baz" +] +OUT + + +my @foo = Dlog_warn { "Look ma, data: $_" } qw{frew bar baz}; +ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_warn passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for Dlog_warn is correct'); +wLook ma, data: "frew" +"bar" +"baz" +OUT + +my $bar = DlogS_warn { "Look ma, data: $_" } [qw{frew bar baz}]; +ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_warn passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for DlogS_warn is correct'); +wLook ma, data: [ + "frew", + "bar", + "baz" +] +OUT + + +my @foo = Dlog_error { "Look ma, data: $_" } qw{frew bar baz}; +ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_error passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for Dlog_error is correct'); +eLook ma, data: "frew" +"bar" +"baz" +OUT + +my $bar = DlogS_error { "Look ma, data: $_" } [qw{frew bar baz}]; +ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_error passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for DlogS_error is correct'); +eLook ma, data: [ + "frew", + "bar", + "baz" +] +OUT + + +my @foo = Dlog_fatal { "Look ma, data: $_" } qw{frew bar baz}; +ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_fatal passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for Dlog_fatal is correct'); +fLook ma, data: "frew" +"bar" +"baz" +OUT + +my $bar = DlogS_fatal { "Look ma, data: $_" } [qw{frew bar baz}]; +ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_fatal passes data through correctly'); +is( $var_log->var, <<'OUT', 'Output for DlogS_fatal is correct'); +fLook ma, data: [ + "frew", + "bar", + "baz" +] +OUT + diff --git a/t/log.t b/t/log.t index 6fc26fe..667874b 100644 --- a/t/log.t +++ b/t/log.t @@ -31,17 +31,44 @@ SETLOGGER: { SETWITHLOGGER: { with_logger $var_logger1 => sub { - log_debug { 'nothing again!' } + log_debug { 'nothing again!' }; + set_logger(sub { $var_logger3 }); + log_debug { 'this is a set inside a with' }; }; is( $var_logger1->var, 'dnothing again!', 'inner scoped logger works after using set_logger' ); + is( $var_logger3->var, 'dthis is a set inside a with', + 'set inside with works' + ); + log_debug { 'frioux!' }; is( $var_logger3->var, 'dfrioux!', q{set_logger's logger comes back after scoped logger} ); } +VANILLA: { + log_trace { 'fiSMBoC' }; + is( $var_logger3->var, 'tfiSMBoC', 'trace works'); + + log_debug { 'fiSMBoC' }; + is( $var_logger3->var, 'dfiSMBoC', 'debug works'); + + log_info { 'fiSMBoC' }; + is( $var_logger3->var, 'ifiSMBoC', 'info works'); + + log_warn { 'fiSMBoC' }; + is( $var_logger3->var, 'wfiSMBoC', 'warn works'); + + log_error { 'fiSMBoC' }; + is( $var_logger3->var, 'efiSMBoC', 'error works'); + + log_fatal { 'fiSMBoC' }; + is( $var_logger3->var, 'ffiSMBoC', 'fatal works'); + +} + ok(!eval { Log::Contextual->import; 1 }, 'Blank Log::Contextual import dies');