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