Added the supplied argument to the regexp fallback warning for easier debugging
[catagits/Catalyst-Runtime.git] / t / unit_core_component.t
CommitLineData
75aff34d 1use Test::More tests => 14;
fbcc39ad 2use strict;
3use warnings;
4
5use_ok('Catalyst');
6
7my @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 });
e96dc5be 15
16 # this is so $c->log->warn will work
17 __PACKAGE__->setup_log;
fbcc39ad 18}
19
20is(MyApp->comp('MyApp::V::View'), 'MyApp::V::View', 'Explicit return ok');
21
22is(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok');
23
24is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok');
25
6977fbff 26# regexp fallback
e96dc5be 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}
fbcc39ad 35
36is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok');
37
6977fbff 38# Is this desired behaviour?
fbcc39ad 39is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok');
6977fbff 40
41# regexp behavior
42{
43 is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model'], 'regexp ok' );
75aff34d 44 is_deeply( [ MyApp->comp('MyApp::V::View$') ], [ 'MyApp::V::View' ], 'Explicit return ok');
45 is_deeply( [ MyApp->comp('MyApp::C::Controller$') ], [ 'MyApp::C::Controller' ], 'Explicit return ok');
46 is_deeply( [ MyApp->comp('MyApp::M::Model$') ], [ 'MyApp::M::Model' ], 'Explicit return ok');
6977fbff 47}
48
49# multiple returns
50{
51 my @expected = qw( MyApp::C::Controller MyApp::M::Model );
52 is_deeply( [ MyApp->comp( qr{::[MC]::} ) ], \@expected, 'multiple results fro regexp ok' );
53}
54
55# failed search
56{
57 is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' );
58}
59