Optionally update conflicting modules by adding them to requires. This is disabled...
[catagits/Catalyst-Runtime.git] / t / unit_core_setup_log.t
CommitLineData
812082c6 1use strict;
2use warnings;
3
abf65c2a 4use Test::More tests => 30;
812082c6 5use Test::Exception;
6
7use Catalyst ();
8
9sub mock_app {
10 my $name = shift;
abf65c2a 11 warn("Setting up mock application: $name\n");
812082c6 12 my $meta = Moose->init_meta( for_class => $name );
13 $meta->superclasses('Catalyst');
14 return $meta->name;
15}
16
17sub test_log_object {
18 my ($log, %expected) = @_;
19 foreach my $level (keys %expected) {
20 my $method_name = "is_$level";
21 if ($expected{$level}) {
22 ok( $log->$method_name(), "Level $level on" );
23 }
24 else {
25 ok( !$log->$method_name(), "Level $level off" );
26 }
27 }
28}
29
30local %ENV; # Ensure blank or someone, somewhere will fail..
31
32{
33 my $app = mock_app('TestLogAppParseLevels');
34 $app->setup_log('error,warn');
35 ok !$app->debug, 'Not in debug mode';
36 test_log_object($app->log,
37 fatal => 0, # WTF - I thought log levels were additive these days,
38 # or do I not understand the patch which pupported to make
39 # them so?
40 error => 1,
41 warn => 1,
42 info => 0,
43 debug => 0,
44 );
45}
46{
47 local %ENV = ( CATALYST_DEBUG => 1 );
48 my $app = mock_app('TestLogAppDebugEnvSet');
49 $app->setup_log('');
50 ok $app->debug, 'In debug mode';
51 test_log_object($app->log,
abf65c2a 52 fatal => 0,
53 error => 0,
54 warn => 0,
55 info => 0,
812082c6 56 debug => 1,
57 );
58}
59{
60 local %ENV = ( CATALYST_DEBUG => 0 );
61 my $app = mock_app('TestLogAppDebugEnvUnset');
abf65c2a 62 $app->setup_log('warn');
63 ok !$app->debug, 'Not In debug mode';
64 test_log_object($app->log,
65 fatal => 0,
66 error => 0,
67 warn => 1,
68 info => 0,
69 debug => 0,
70 );
71}
72{
73 my $app = mock_app('TestLogAppEmptyString');
812082c6 74 $app->setup_log('');
75 ok !$app->debug, 'Not In debug mode';
76 test_log_object($app->log,
77 fatal => 0,
78 error => 0,
79 warn => 0,
80 info => 0,
81 debug => 0,
82 );
83}
84{
85 my $app = mock_app('TestLogAppDebugOnly');
86 $app->setup_log('debug');
87 ok $app->debug, 'In debug mode';
88 test_log_object($app->log,
89 fatal => 0,
90 error => 0,
91 warn => 0,
92 info => 0,
93 debug => 1,
94 );
95}