From: Arthur Axel 'fREW' Schmidt Date: Thu, 4 Aug 2011 23:24:25 +0000 (-0500) Subject: add very basic "BaseLogger" test X-Git-Tag: v0.004000~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae70ebeabb55f5c14cfeb3d3a2b402deeb8857d4;p=p5sagit%2FLog-Contextual.git add very basic "BaseLogger" test --- diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 18a84f5..3e95233 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -1 +1 @@ -^(?!script/\w+\.pl|examples/[^\.]+|lib/[\/\w]+\.p(m|od)|inc/|t/\w+\.t|t/\w+\.conf|Makefile.PL$|README$|MANIFEST$|Changes$|META.yml$) +^(?!script/\w+\.pl|examples/[^\.]+|lib/[\/\w]+\.p(m|od)|inc/|t/\w+\.t|t/lib/[\/\w]+\.pm|t/\w+\.conf|Makefile.PL$|README$|MANIFEST$|Changes$|META.yml$) diff --git a/t/base.t b/t/base.t new file mode 100644 index 0000000..873650d --- /dev/null +++ b/t/base.t @@ -0,0 +1,28 @@ +use strict; +use warnings; + +use lib 't/lib'; + +use BaseLogger qw{:log with_logger set_logger}; +use Test::More qw(no_plan); + +my @levels = qw(lol wut zomg); + +VANILLA: { + for (@levels) { + main->can("log_$_")->(sub { 'fiSMBoC' }); + is( $DumbLogger2::var, "[$_] fiSMBoC\n", "$_ works"); + + my @vars = main->can("log_$_")->(sub { 'fiSMBoC: ' . $_[1] }, qw{foo bar baz}); + is( $DumbLogger2::var, "[$_] fiSMBoC: bar\n", "log_$_ works with input"); + ok( eq_array(\@vars, [qw{foo bar baz}]), "log_$_ passes data through correctly"); + + my $val = main->can("logS_$_")->(sub { 'fiSMBoC: ' . $_[0] }, 'foo'); + is( $DumbLogger2::var, "[$_] fiSMBoC: foo\n", "logS_$_ works with input"); + is( $val, 'foo', "logS_$_ passes data through correctly"); + } +} + +ok(!eval { Log::Contextual->import; 1 }, 'Blank Log::Contextual import dies'); + + diff --git a/t/lib/BaseLogger.pm b/t/lib/BaseLogger.pm new file mode 100644 index 0000000..4d0b1bc --- /dev/null +++ b/t/lib/BaseLogger.pm @@ -0,0 +1,22 @@ +package BaseLogger; + +use base 'Log::Contextual'; +use Log::Contextual::SimpleLogger; + +my $logger = DumbLogger2->new; + +sub arg_levels { $_[1] || [qw(lol wut zomg)] } +sub arg_logger { $_[1] || $logger } + +package DumbLogger2; + +our $var; +sub new { bless {}, 'DumbLogger2' } +sub is_wut { 1 } +sub wut { $var = "[wut] $_[1]\n" } +sub is_lol { 1 } +sub lol { $var = "[lol] $_[1]\n" } +sub is_zomg { 1 } +sub zomg { $var = "[zomg] $_[1]\n" } + +1;