X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_setup.t;h=cbc5aaccf6f73932fc21773aa19aafeb2c844b37;hb=08f9c84867673a57d45bacbda7a301734a720fe7;hp=c784c0345c5237c35e430a62dad470298ea73066;hpb=8b05105204b3eaeebf97940006456fd5bd55481c;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_setup.t b/t/unit_core_setup.t index c784c03..cbc5aac 100644 --- a/t/unit_core_setup.t +++ b/t/unit_core_setup.t @@ -1,48 +1,88 @@ use strict; use warnings; +use Class::MOP::Class; use Catalyst::Runtime; -use Test::More tests => 18; +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; +} + +local %ENV = %ENV; + +# Remove all relevant env variables to avoid accidental fail +foreach my $name (grep { /^(CATALYST|TESTAPP)/ } keys %ENV) { + delete $ENV{$name}; +} + +{ + my $app = build_test_app_with_setup('TestAppMyTestDebug', '-Debug'); + + ok my $c = $app->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 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'; +{ + my $app = build_test_app_with_setup('TestAppMyTestLogParam', '-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('TestAppMyTestNoParams'); -TESTAPP: { - package MyTestLog; + 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'; +} +my $log_meta = Class::MOP::Class->create_anon_class( + methods => { map { $_ => sub { 0 } } qw/debug error fatal info warn/ }, +); +{ + package TestAppWithOwnLogger; use base qw/Catalyst/; - __PACKAGE__->setup( - '-Log=warn,error,fatal' - ); + __PACKAGE__->log($log_meta->new_object); + __PACKAGE__->setup('-Debug'); } -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'; +ok my $c = TestAppWithOwnLogger->new, 'Get with own logger app object'; +ok $c->debug, '$c->debug is true'; +