4 use Test::More tests => 18;
5 use Class::Load 'is_class_loaded';
9 BEGIN { use_ok("Catalyst::Utils") };
12 package This::Module::Is::Not::In::Inc::But::Does::Exist;
17 $SIG{__WARN__} = sub {
18 return if $_[0] =~ /Subroutine (?:un|re|)initialize redefined at .*C3\.pm/;
22 ok( !is_class_loaded("TestApp::View::Dump"), "component not yet loaded" );
24 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump");
26 ok( is_class_loaded("TestApp::View::Dump"), "loaded ok" );
27 is( $warnings, 0, "no warnings emitted" );
31 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump");
32 is( $warnings, 0, "calling again doesn't reaload" );
34 ok( !is_class_loaded("TestApp::View::Dump::Request"), "component not yet loaded" );
36 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Request");
37 ok( is_class_loaded("TestApp::View::Dump::Request"), "loaded ok" );
39 is( $warnings, 0, "calling again doesn't reaload" );
42 eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Probably::Not::There") };
43 ok( $@, "doesn't defatalize" );
44 like( $@, qr/There\.pm.*\@INC/, "error looks right" );
47 eval { Catalyst::Utils::ensure_class_loaded("__PACKAGE__") };
48 ok( $@, "doesn't defatalize" );
49 like( $@, qr/__PACKAGE__\.pm.*\@INC/, "errors sanely on __PACKAGE__.pm" );
52 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Response");
53 is( $@, "foo", '$@ is untouched' );
56 eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Not::In::Inc::But::Does::Exist") };
57 ok( !$@, "no error when loading non existent .pm that *does* have a symbol table entry" );
60 eval { Catalyst::Utils::ensure_class_loaded('Silly::File::.#Name') };
61 like($@, qr/Malformed class Name/, 'errored when attempting to load a file beginning with a .');
64 eval { Catalyst::Utils::ensure_class_loaded('Silly::File::Name.pm') };
65 like($@, qr/Malformed class Name/, 'errored sanely when given a classname ending in .pm');
69 Catalyst::Utils::ensure_class_loaded("NullPackage");
70 is( $warnings, 1, 'Loading a package which defines no symbols warns');
71 is( $@, undef, '$@ still undef' );