From: Arthur Axel 'fREW' Schmidt Date: Tue, 10 Sep 2013 21:55:00 +0000 (-0500) Subject: ensure that gross code will not creep in X-Git-Tag: v0.006001~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=489f71b2de7921cfe1f20ebd2745f15fddcaa747;p=p5sagit%2FLog-Contextual.git ensure that gross code will not creep in --- diff --git a/.perltidyrc b/.perltidyrc index a74e3c3..ef9d586 100644 --- a/.perltidyrc +++ b/.perltidyrc @@ -1,4 +1,3 @@ --st -se -i=3 -bar diff --git a/.travis.yml b/.travis.yml index b8aff8c..f3629da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ perl: install: - export RELEASE_TESTING=1 AUTOMATED_TESTING=1 AUTHOR_TESTING=1 HARNESS_OPTIONS=j10:c HARNESS_TIMER=1 - cpanm --quiet --notest --installdeps . - - cpanm -nq Devel::Cover::Report::Coveralls + - cpanm -nq Devel::Cover::Report::Coveralls Test::PerlTidy script: - PERL5OPT=-MDevel::Cover=-coverage,statement,branch,condition,path,subroutine prove -lrsv t - cover diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index cc521c8..e438ef0 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -4,7 +4,8 @@ use strict; use warnings; our $VERSION = '0.006000'; -$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases +$VERSION = eval $VERSION + if $VERSION =~ /_/; # numify for warning-free dev releases my @levels = qw(debug trace warn info error fatal); @@ -27,10 +28,7 @@ eval { # export anything but the levels selected sub ____ { } -exports ('____', - @dlog, @log, - qw( set_logger with_logger ) -); +exports('____', @dlog, @log, qw( set_logger with_logger )); export_tag dlog => ('____'); export_tag log => ('____'); @@ -183,10 +181,10 @@ for (qw(set with)) { no strict 'refs'; my $sub = "${_}_logger"; *{"Log::Contextual::$sub"} = sub { - die "$sub is no longer a direct sub in Log::Contextual. " . - 'Note that this feature was never tested nor documented. ' . - "Please fix your code to import $sub instead of trying to use it directly" - } + die "$sub is no longer a direct sub in Log::Contextual. " + . 'Note that this feature was never tested nor documented. ' + . "Please fix your code to import $sub instead of trying to use it directly" + } } 1; diff --git a/t/default_import.t b/t/default_import.t index a7cb27c..0db43c9 100644 --- a/t/default_import.t +++ b/t/default_import.t @@ -11,15 +11,19 @@ my @levels = qw(lol wut zomg); VANILLA: { for (@levels) { main->can("log_$_")->(sub { 'fiSMBoC' }); - is( $DumbLogger2::var, "[$_] fiSMBoC\n", "$_ works"); + 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 @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"); + is($DumbLogger2::var, "[$_] fiSMBoC: foo\n", "logS_$_ works with input"); + is($val, 'foo', "logS_$_ passes data through correctly"); } } diff --git a/t/default_logger.t b/t/default_logger.t index b509cd2..20c4e50 100644 --- a/t/default_logger.t +++ b/t/default_logger.t @@ -8,8 +8,8 @@ my $var1; my $var2; my $var3; my $var_logger1 = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace debug info warn error fatal)], - coderef => sub { $var1 = shift }, + levels => [qw(trace debug info warn error fatal)], + coderef => sub { $var1 = shift }, }); my $var_logger2; diff --git a/t/easy.t b/t/easy.t index 8c18276..056b4ef 100644 --- a/t/easy.t +++ b/t/easy.t @@ -4,17 +4,17 @@ use warnings; use Test::More; use lib 't/lib'; -use My::Module; # makes use of Log::Contextual::Easy::Default; -use My::Module2; # makes use of Log::Contextual::Easy::Package; +use My::Module; # makes use of Log::Contextual::Easy::Default; +use My::Module2; # makes use of Log::Contextual::Easy::Package; # capture logging messages of My::Module, mapping "[...] xxx" to "...$sep" sub logshort($$) { - my ($cap, $sep) = @_; - sub { - local $_ = shift; - s/^\[(.+)\] (xxx|"xxx")\n$/$1$sep/; - $$cap .= $_; - } + my ($cap, $sep) = @_; + sub { + local $_ = shift; + s/^\[(.+)\] (xxx|"xxx")\n$/$1$sep/; + $$cap .= $_; + } } # capture warnings @@ -22,47 +22,53 @@ my ($cap_warn, $cap_with, $cap_set); local $SIG{__WARN__} = logshort \$cap_warn, '!'; { - My::Module::log(); - My::Module2::log(); - is($cap_warn, undef, 'no logging by default'); + My::Module::log(); + My::Module2::log(); + is($cap_warn, undef, 'no logging by default'); } { - local $ENV{MY_MODULE_UPTO} = 'info'; - local $ENV{MY_MODULE2_UPTO} = 'info'; - My::Module::log(); - My::Module2::log(); - is($cap_warn, "info!warn!error!fatal!info!warn!error!fatal!", 'WarnLogger enabled via ENV'); - $cap_warn = ''; + local $ENV{MY_MODULE_UPTO} = 'info'; + local $ENV{MY_MODULE2_UPTO} = 'info'; + My::Module::log(); + My::Module2::log(); + is( + $cap_warn, + "info!warn!error!fatal!info!warn!error!fatal!", + 'WarnLogger enabled via ENV' + ); + $cap_warn = ''; } { - use Log::Contextual::SimpleLogger; - use Log::Contextual qw(with_logger set_logger); + use Log::Contextual::SimpleLogger; + use Log::Contextual qw(with_logger set_logger); - set_logger( Log::Contextual::SimpleLogger->new({ - levels => [qw(info warn error)], - coderef => logshort \$cap_set, '/' - }) ); + set_logger( + Log::Contextual::SimpleLogger->new({ + levels => [qw(info warn error)], + coderef => logshort \$cap_set, + '/' + })); - my $with_logger = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace info fatal)], - coderef => logshort \$cap_with, '|' - }); - - with_logger $with_logger => sub { - My::Module::log(); - My::Module2::log(); # will not be overridden - }; - is($cap_with, 'trace|info|fatal|', 'with_logger'); + my $with_logger = Log::Contextual::SimpleLogger->new({ + levels => [qw(trace info fatal)], + coderef => logshort \$cap_with, + '|' + }); - My::Module::log(); - My::Module2::log(); # will not be overridden - is($cap_set, 'info/warn/error/', 'set_logger'); + with_logger $with_logger => sub { + My::Module::log(); + My::Module2::log(); # will not be overridden + }; + is($cap_with, 'trace|info|fatal|', 'with_logger'); - is($cap_warn, '', 'no warnings if with_logger or set_logger'); + My::Module::log(); + My::Module2::log(); # will not be overridden + is($cap_set, 'info/warn/error/', 'set_logger'); + + is($cap_warn, '', 'no warnings if with_logger or set_logger'); } done_testing; - diff --git a/t/eg.t b/t/eg.t index e28a116..bd73173 100644 --- a/t/eg.t +++ b/t/eg.t @@ -9,18 +9,18 @@ my ($var1, $var2, $var3); my $complex_dispatcher = do { my $l1 = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace debug info warn error fatal)], - coderef => sub { $var1 = shift }, + levels => [qw(trace debug info warn error fatal)], + coderef => sub { $var1 = shift }, }); my $l2 = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace debug info warn error fatal)], - coderef => sub { $var2 = shift }, + levels => [qw(trace debug info warn error fatal)], + coderef => sub { $var2 = shift }, }); my $l3 = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace debug info warn error fatal)], - coderef => sub { $var3 = shift }, + levels => [qw(trace debug info warn error fatal)], + coderef => sub { $var3 = shift }, }); my %registry = ( diff --git a/t/lib/DefaultImportLogger.pm b/t/lib/DefaultImportLogger.pm index 314c5fc..acb6d8d 100644 --- a/t/lib/DefaultImportLogger.pm +++ b/t/lib/DefaultImportLogger.pm @@ -6,18 +6,18 @@ use Log::Contextual::SimpleLogger; my $logger = DumbLogger2->new; sub default_import { ':log' } -sub arg_levels { $_[1] || [qw(lol wut zomg)] } -sub arg_logger { $_[1] || $logger } +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_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" } +sub zomg { $var = "[zomg] $_[1]\n" } 1; diff --git a/t/lib/My/Module.pm b/t/lib/My/Module.pm index c7c6754..3110812 100644 --- a/t/lib/My/Module.pm +++ b/t/lib/My/Module.pm @@ -2,12 +2,10 @@ package My::Module; use Log::Contextual::Easy::Default; sub log { - Dlog_fatal { $_ } - DlogS_error { $_ } - logS_warn { $_[0] } - logS_info { $_[0] } - log_debug { $_[0] } - log_trace { $_[0] } 'xxx'; + Dlog_fatal { $_ } + DlogS_error { $_ } + logS_warn { $_[0] } + logS_info { $_[0] } log_debug { $_[0] } log_trace { $_[0] } 'xxx'; } 1; diff --git a/t/lib/My/Module2.pm b/t/lib/My/Module2.pm index f8b0f4d..e36baa8 100644 --- a/t/lib/My/Module2.pm +++ b/t/lib/My/Module2.pm @@ -2,12 +2,10 @@ package My::Module2; use Log::Contextual::Easy::Package; sub log { - Dlog_fatal { $_ } - DlogS_error { $_ } - logS_warn { $_[0] } - logS_info { $_[0] } - log_debug { $_[0] } - log_trace { $_[0] } 'xxx'; + Dlog_fatal { $_ } + DlogS_error { $_ } + logS_warn { $_[0] } + logS_info { $_[0] } log_debug { $_[0] } log_trace { $_[0] } 'xxx'; } 1; diff --git a/t/log.t b/t/log.t index 8303a43..2812cf9 100644 --- a/t/log.t +++ b/t/log.t @@ -11,18 +11,18 @@ my $var1; my $var2; my $var3; my $var_logger1 = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace debug info warn error fatal)], - coderef => sub { $var1 = shift }, + levels => [qw(trace debug info warn error fatal)], + coderef => sub { $var1 = shift }, }); my $var_logger2 = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace debug info warn error fatal)], - coderef => sub { $var2 = shift }, + levels => [qw(trace debug info warn error fatal)], + coderef => sub { $var2 = shift }, }); my $var_logger3 = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace debug info warn error fatal)], - coderef => sub { $var3 = shift }, + levels => [qw(trace debug info warn error fatal)], + coderef => sub { $var3 = shift }, }); SETLOGGER: { diff --git a/t/package_logger.t b/t/package_logger.t index 27823c7..b52580e 100644 --- a/t/package_logger.t +++ b/t/package_logger.t @@ -8,8 +8,8 @@ my $var1; my $var2; my $var3; my $var_logger1 = Log::Contextual::SimpleLogger->new({ - levels => [qw(trace debug info warn error fatal)], - coderef => sub { $var1 = shift }, + levels => [qw(trace debug info warn error fatal)], + coderef => sub { $var1 = shift }, }); my $var_logger2; diff --git a/t/perltidy.t b/t/perltidy.t new file mode 100644 index 0000000..007afee --- /dev/null +++ b/t/perltidy.t @@ -0,0 +1,19 @@ +#!perl + +use strict; +use warnings; + +use Test::More; + +plan skip_all => 'Set TIDY_TESTING if you want to run this test' + unless $ENV{TIDY_TESTING}; + +require Test::PerlTidy; + +Test::PerlTidy::run_tests( + path => '.', + perltidyrc => '.perltidyrc', + exclude => ['inc/'], +); + +done_testing; diff --git a/t/simplelogger.t b/t/simplelogger.t index 842163a..8425a3e 100644 --- a/t/simplelogger.t +++ b/t/simplelogger.t @@ -70,8 +70,8 @@ ok( my $response; my $l2 = Log::Contextual::SimpleLogger->new({ - levels => [qw{trace debug info warn error fatal}], - coderef => sub { $response = $_[0] }, + levels => [qw{trace debug info warn error fatal}], + coderef => sub { $response = $_[0] }, }); { local $SIG{__WARN__} = sub { }; # do this just to hide warning for tests