add a test for warnings from comp()
[catagits/Catalyst-Runtime.git] / t / unit_core_component.t
1 use Test::More tests => 11;
2 use strict;
3 use warnings;
4
5 use_ok('Catalyst');
6
7 my @complist = map { "MyApp::$_"; } qw/C::Controller M::Model V::View/;
8
9 {
10   package MyApp;
11
12   use base qw/Catalyst/;
13
14   __PACKAGE__->components({ map { ($_, $_) } @complist });
15
16   # this is so $c->log->warn will work
17   __PACKAGE__->setup_log;
18 }
19
20 is(MyApp->comp('MyApp::V::View'), 'MyApp::V::View', 'Explicit return ok');
21
22 is(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok');
23
24 is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok');
25
26 # regexp fallback
27 {
28     my $warnings = 0;
29     no warnings 'redefine';
30     local *Catalyst::Log::warn = sub { $warnings++ };
31
32     is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok');
33     ok( $warnings, 'regexp fallback for comp() warns' );
34 }
35
36 is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok');
37
38 # Is this desired behaviour?
39 is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok');
40
41 # regexp behavior
42 {
43     is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model'], 'regexp ok' );
44 }
45
46 # multiple returns
47 {
48     my @expected = qw( MyApp::C::Controller MyApp::M::Model );
49     is_deeply( [ MyApp->comp( qr{::[MC]::} ) ], \@expected, 'multiple results fro regexp ok' );
50 }
51
52 # failed search
53 {
54     is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' );
55 }
56