Commit | Line | Data |
812082c6 |
1 | use strict; |
2 | use warnings; |
3 | |
abf65c2a |
4 | use Test::More tests => 30; |
812082c6 |
5 | use Test::Exception; |
6 | |
7 | use Catalyst (); |
8 | |
9 | sub mock_app { |
10 | my $name = shift; |
4cb5d29f |
11 | print "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 | |
17 | sub 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 | |
30 | local %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, |
e2422920 |
52 | fatal => 1, |
53 | error => 1, |
54 | warn => 1, |
55 | info => 1, |
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'; |
d31581c6 |
76 | TODO: { |
77 | local $TODO = 'THis is insane'; |
78 | test_log_object($app->log, |
79 | fatal => 0, |
80 | error => 0, |
81 | warn => 0, |
82 | info => 0, |
83 | debug => 0, |
84 | ); |
85 | } |
812082c6 |
86 | } |
87 | { |
88 | my $app = mock_app('TestLogAppDebugOnly'); |
89 | $app->setup_log('debug'); |
90 | ok $app->debug, 'In debug mode'; |
91 | test_log_object($app->log, |
e2422920 |
92 | fatal => 1, |
93 | error => 1, |
94 | warn => 1, |
95 | info => 1, |
812082c6 |
96 | debug => 1, |
97 | ); |
98 | } |