include test for failure mode
[catagits/Catalyst-Runtime.git] / t / unit_core_setup.t
CommitLineData
0fa676a7 1use strict;
2use warnings;
3use Catalyst::Runtime;
4
5baa3bbc 5use Test::More tests => 20;
0fa676a7 6
7{
8 # Silence the log.
9 no warnings 'redefine';
10 *Catalyst::Log::_send_to_log = sub {};
11}
12
13TESTDEBUG: {
14 package MyTestDebug;
8b051052 15 use base qw/Catalyst/;
0fa676a7 16 __PACKAGE__->setup(
17 '-Debug',
18 );
19}
20
21ok my $c = MyTestDebug->new, 'Get debug app object';
22ok my $log = $c->log, 'Get log object';
23isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object';
24ok !$log->is_warn, 'Warnings should be disabled';
25ok !$log->is_error, 'Errors should be disabled';
26ok !$log->is_fatal, 'Fatal errors should be disabled';
27ok !$log->is_info, 'Info should be disabled';
28ok $log->is_debug, 'Debugging should be enabled';
29can_ok 'MyTestDebug', 'debug';
30ok +MyTestDebug->debug, 'And it should return true';
31
32
33TESTAPP: {
34 package MyTestLog;
8b051052 35 use base qw/Catalyst/;
0fa676a7 36 __PACKAGE__->setup(
37 '-Log=warn,error,fatal'
38 );
39}
40
41ok $c = MyTestLog->new, 'Get log app object';
42ok $log = $c->log, 'Get log object';
43isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object';
44ok $log->is_warn, 'Warnings should be enabled';
45ok $log->is_error, 'Errors should be enabled';
46ok $log->is_fatal, 'Fatal errors should be enabled';
47ok !$log->is_info, 'Info should be disabled';
48ok !$log->is_debug, 'Debugging should be disabled';
5baa3bbc 49
50TESTOWNLOGGER: {
51 package MyTestAppWithOwnLogger;
52 use base qw/Catalyst/;
53 use Test::MockObject;
54 my $log = Test::MockObject->new;
55 $log->set_false(qw/debug error fatal info warn/);
56 __PACKAGE__->log($log);
57 __PACKAGE__->setup('-Debug');
58}
59
60ok $c = MyTestAppWithOwnLogger->new, 'Get with own logger app object';
61ok $c->debug, '$c->debug is true';