docs and allow ../
[catagits/Catalyst-Runtime.git] / t / unit_utils_load_class.t
CommitLineData
d9183506 1use strict;
2use warnings;
3
54ba55d5 4use Test::More;
e7399d8b 5use Class::Load 'is_class_loaded';
d9183506 6use lib "t/lib";
7
54ba55d5 8BEGIN {
9 if ($^O =~ m/^MSWin/) {
10 plan skip_all => 'Skipping this test on Windows until someone with Windows has time to fix it';
11 }
12
13 use_ok("Catalyst::Utils");
14}
d9183506 15
16{
17 package This::Module::Is::Not::In::Inc::But::Does::Exist;
18 sub moose {};
19}
20
21my $warnings = 0;
c48e4d53 22$SIG{__WARN__} = sub {
23 return if $_[0] =~ /Subroutine (?:un|re|)initialize redefined at .*C3\.pm/;
24 $warnings++;
25};
d9183506 26
e7399d8b 27ok( !is_class_loaded("TestApp::View::Dump"), "component not yet loaded" );
d9183506 28
29Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump");
30
e7399d8b 31ok( is_class_loaded("TestApp::View::Dump"), "loaded ok" );
d9183506 32is( $warnings, 0, "no warnings emitted" );
33
34$warnings = 0;
35
36Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump");
37is( $warnings, 0, "calling again doesn't reaload" );
38
e7399d8b 39ok( !is_class_loaded("TestApp::View::Dump::Request"), "component not yet loaded" );
d9183506 40
41Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Request");
e7399d8b 42ok( is_class_loaded("TestApp::View::Dump::Request"), "loaded ok" );
d9183506 43
44is( $warnings, 0, "calling again doesn't reaload" );
45
46undef $@;
47eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Probably::Not::There") };
48ok( $@, "doesn't defatalize" );
49like( $@, qr/There\.pm.*\@INC/, "error looks right" );
50
7a1958eb 51undef $@;
52eval { Catalyst::Utils::ensure_class_loaded("__PACKAGE__") };
53ok( $@, "doesn't defatalize" );
54like( $@, qr/__PACKAGE__\.pm.*\@INC/, "errors sanely on __PACKAGE__.pm" );
55
d9183506 56$@ = "foo";
57Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Response");
58is( $@, "foo", '$@ is untouched' );
59
60undef $@;
61eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Not::In::Inc::But::Does::Exist") };
62ok( !$@, "no error when loading non existent .pm that *does* have a symbol table entry" );
63
59ede84e 64undef $@;
65eval { Catalyst::Utils::ensure_class_loaded('Silly::File::.#Name') };
66like($@, qr/Malformed class Name/, 'errored when attempting to load a file beginning with a .');
67
68undef $@;
69eval { Catalyst::Utils::ensure_class_loaded('Silly::File::Name.pm') };
70like($@, qr/Malformed class Name/, 'errored sanely when given a classname ending in .pm');
71
f55d1491 72undef $@;
73$warnings = 0;
74Catalyst::Utils::ensure_class_loaded("NullPackage");
75is( $warnings, 1, 'Loading a package which defines no symbols warns');
76is( $@, undef, '$@ still undef' );
77
54ba55d5 78done_testing;