X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_setup.t;h=1e6e5729f01f41ef566c35917190a3e7b9780ac7;hb=3932d8818a3c5112315a8757b6db7a3678755f7e;hp=70b649ee14df8e14aee6be1a9a8b13c0eff0778e;hpb=5baa3bbcb8bea403665bceaa82f819905f0b501f;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_setup.t b/t/unit_core_setup.t index 70b649e..1e6e572 100644 --- a/t/unit_core_setup.t +++ b/t/unit_core_setup.t @@ -2,52 +2,72 @@ use strict; use warnings; use Catalyst::Runtime; -use Test::More tests => 20; +use Test::More tests => 29; { # Silence the log. - no warnings 'redefine'; - *Catalyst::Log::_send_to_log = sub {}; + my $meta = Catalyst::Log->meta; + $meta->make_mutable; + $meta->remove_method('_send_to_log'); + $meta->add_method('_send_to_log', sub {}); } -TESTDEBUG: { - package MyTestDebug; - use base qw/Catalyst/; - __PACKAGE__->setup( - '-Debug', - ); +sub build_test_app_with_setup { + my ($name, @flags) = @_; + my $flags = '(' . join(', ', map { "'".$_."'" } @flags) . ')'; + $flags = '' if $flags eq '()'; + eval qq{ + package $name; + use Catalyst $flags; + $name->setup; + }; + die $@ if $@; + return $name; } -ok my $c = MyTestDebug->new, 'Get debug app object'; -ok my $log = $c->log, 'Get log object'; -isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object'; -ok !$log->is_warn, 'Warnings should be disabled'; -ok !$log->is_error, 'Errors should be disabled'; -ok !$log->is_fatal, 'Fatal errors should be disabled'; -ok !$log->is_info, 'Info should be disabled'; -ok $log->is_debug, 'Debugging should be enabled'; -can_ok 'MyTestDebug', 'debug'; -ok +MyTestDebug->debug, 'And it should return true'; +local %ENV; # Don't allow env variables to mess us up. +{ + my $app = build_test_app_with_setup('MyTestDebug', '-Debug'); -TESTAPP: { - package MyTestLog; - use base qw/Catalyst/; - __PACKAGE__->setup( - '-Log=warn,error,fatal' - ); + ok my $c = MyTestDebug->new, 'Get debug app object'; + ok my $log = $c->log, 'Get log object'; + isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object'; + ok $log->is_warn, 'Warnings should be enabled'; + ok $log->is_error, 'Errors should be enabled'; + ok $log->is_fatal, 'Fatal errors should be enabled'; + ok $log->is_info, 'Info should be enabled'; + ok $log->is_debug, 'Debugging should be enabled'; + ok $app->debug, 'debug method should return true'; } -ok $c = MyTestLog->new, 'Get log app object'; -ok $log = $c->log, 'Get log object'; -isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object'; -ok $log->is_warn, 'Warnings should be enabled'; -ok $log->is_error, 'Errors should be enabled'; -ok $log->is_fatal, 'Fatal errors should be enabled'; -ok !$log->is_info, 'Info should be disabled'; -ok !$log->is_debug, 'Debugging should be disabled'; +{ + my $app = build_test_app_with_setup('MyTestLogParam', '-Log=warn,error,fatal'); + + ok my $c = $app->new, 'Get log app object'; + ok my $log = $c->log, 'Get log object'; + isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object'; + ok $log->is_warn, 'Warnings should be enabled'; + ok $log->is_error, 'Errors should be enabled'; + ok $log->is_fatal, 'Fatal errors should be enabled'; + ok !$log->is_info, 'Info should be disabled'; + ok !$log->is_debug, 'Debugging should be disabled'; + ok !$c->debug, 'Catalyst debugging is off'; +} +{ + my $app = build_test_app_with_setup('MyTestNoParams'); -TESTOWNLOGGER: { + ok my $c = $app->new, 'Get log app object'; + ok my $log = $c->log, 'Get log object'; + isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object'; + ok $log->is_warn, 'Warnings should be enabled'; + ok $log->is_error, 'Errors should be enabled'; + ok $log->is_fatal, 'Fatal errors should be enabled'; + ok $log->is_info, 'Info should be enabled'; + ok $log->is_debug, 'Debugging should be enabled'; + ok !$c->debug, 'Catalyst debugging turned off'; +} +{ package MyTestAppWithOwnLogger; use base qw/Catalyst/; use Test::MockObject; @@ -57,5 +77,6 @@ TESTOWNLOGGER: { __PACKAGE__->setup('-Debug'); } -ok $c = MyTestAppWithOwnLogger->new, 'Get with own logger app object'; +ok my $c = MyTestAppWithOwnLogger->new, 'Get with own logger app object'; ok $c->debug, '$c->debug is true'; +