7 use lib "$FindBin::Bin/../lib";
9 use Test::More tests => 34;
14 my $meta = Catalyst::Log->meta;
16 $meta->remove_method('_send_to_log');
17 $meta->add_method('_send_to_log', sub {});
20 sub build_test_app_with_setup {
21 my ($name, @flags) = @_;
22 my $flags = '(' . join(', ', map { "'".$_."'" } @flags) . ')';
23 $flags = '' if $flags eq '()';
35 # Remove all relevant env variables to avoid accidental fail
36 foreach my $name (grep { /^(CATALYST|TESTAPP)/ } keys %ENV) {
41 my $app = build_test_app_with_setup('TestAppMyTestDebug', '-Debug');
43 ok my $c = $app->new, 'Get debug app object';
44 ok my $log = $c->log, 'Get log object';
45 isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object';
46 ok $log->is_warn, 'Warnings should be enabled';
47 ok $log->is_error, 'Errors should be enabled';
48 ok $log->is_fatal, 'Fatal errors should be enabled';
49 ok $log->is_info, 'Info should be enabled';
50 ok $log->is_debug, 'Debugging should be enabled';
51 ok $app->debug, 'debug method should return true';
55 my $app = build_test_app_with_setup('TestAppMyTestLogParam', '-Log=warn,error,fatal');
57 ok my $c = $app->new, 'Get log app object';
58 ok my $log = $c->log, 'Get log object';
59 isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object';
60 ok $log->is_warn, 'Warnings should be enabled';
61 ok $log->is_error, 'Errors should be enabled';
62 ok $log->is_fatal, 'Fatal errors should be enabled';
63 ok !$log->is_info, 'Info should be disabled';
64 ok !$log->is_debug, 'Debugging should be disabled';
65 ok !$c->debug, 'Catalyst debugging is off';
68 my $app = build_test_app_with_setup('TestAppMyTestNoParams');
70 ok my $c = $app->new, 'Get log app object';
71 ok my $log = $c->log, 'Get log object';
72 isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object';
73 ok $log->is_warn, 'Warnings should be enabled';
74 ok $log->is_error, 'Errors should be enabled';
75 ok $log->is_fatal, 'Fatal errors should be enabled';
76 ok $log->is_info, 'Info should be enabled';
77 ok $log->is_debug, 'Debugging should be enabled';
78 ok !$c->debug, 'Catalyst debugging turned off';
80 my $log_meta = Class::MOP::Class->create_anon_class(
81 methods => { map { $_ => sub { 0 } } qw/debug error fatal info warn/ },
84 package TestAppWithOwnLogger;
85 use base qw/Catalyst/;
86 __PACKAGE__->log($log_meta->new_object);
87 __PACKAGE__->setup('-Debug');
90 ok my $c = TestAppWithOwnLogger->new, 'Get with own logger app object';
91 ok $c->debug, '$c->debug is true';
94 = 'These tests will not pass until Catalyst stops supporting old (NEXT-using) plugins';
97 local $SIG{__WARN__} = sub {
98 my $warn = join '', @_;
99 die $warn if $warn =~ /Deep recursion/;
103 use_ok 'TestAppSetupRecursion';
106 is $TestAppSetupRecursion::AfterCount, 1, 'setup modifier was only called once';
110 local $SIG{__WARN__} = sub {
111 my $warn = join '', @_;
112 die $warn if $warn =~ /Deep recursion/;
116 use_ok 'TestAppSetupRecursionImmutable';
119 is $TestAppSetupRecursionImmutable::AfterCount, 1, 'setup modifier was only called once';
121 ok( TestAppSetupRecursionImmutable->meta->is_immutable,
122 'package is still immutable after setup is called');