Detect redispatch exceptions by a class check, not by checking the exception message.
[catagits/Catalyst-Runtime.git] / t / unit_core_setup_stats.t
CommitLineData
7c79dcf3 1use strict;
2use warnings;
3
4use Test::More tests => 5;
cdb2bf9c 5use Class::MOP::Class;
7c79dcf3 6
7use Catalyst ();
8
9my %log_messages; # TODO - Test log messages as expected.
cdb2bf9c 10my $mock_log = Class::MOP::Class->create_anon_class(
11 methods => {
12 map { my $level = $_;
13 $level => sub {
14 $log_messages{$level} ||= [];
15 push(@{ $log_messages{$level} }, $_[1]);
16 },
17 }
18 qw/debug info warn error fatal/,
19 },
20)->new_object;
7c79dcf3 21
22sub mock_app {
23 my $name = shift;
24 %log_messages = (); # Flatten log messages.
25 print "Setting up mock application: $name\n";
26 my $meta = Moose->init_meta( for_class => $name );
27 $meta->superclasses('Catalyst');
28 $meta->add_method('log', sub { $mock_log });
29 return $meta->name;
30}
31
32local %ENV; # Ensure blank or someone, somewhere will fail..
33
34{
35 my $app = mock_app('TestNoStats');
36 $app->setup_stats();
37 ok !$app->use_stats, 'stats off by default';
38}
39{
40 my $app = mock_app('TestStats');
41 $app->setup_stats(1);
42 ok $app->use_stats, 'stats on if you say >setup_stats(1)';
43}
44{
45 my $app = mock_app('TestStatsDebugTurnsStatsOn');
46 $app->meta->add_method('debug' => sub { 1 });
47 $app->setup_stats();
48 ok $app->use_stats, 'debug on turns stats on';
49}
50{
51 local %ENV = ( CATALYST_STATS => 1 );
52 my $app = mock_app('TestStatsAppStatsEnvSet');
53 $app->setup_stats();
54 ok $app->use_stats, 'ENV turns stats on';
55}
56{
57 local %ENV = ( CATALYST_STATS => 0 );
58 my $app = mock_app('TestStatsAppStatsEnvUnset');
59 $app->meta->add_method('debug' => sub { 1 });
60 $app->setup_stats(1);
61 ok !$app->use_stats, 'ENV turns stats off, even when debug on and ->setup_stats(1)';
62}
63