6 use Test::More tests => 18;
11 BEGIN { use_ok("Catalyst::Utils") };
14 package This::Module::Is::Not::In::Inc::But::Does::Exist;
19 $SIG{__WARN__} = sub {
20 return if $_[0] =~ /Subroutine (?:un|re|)initialize redefined at .*C3\.pm/;
24 ok( !Class::MOP::is_class_loaded("TestApp::View::Dump"), "component not yet loaded" );
26 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump");
28 ok( Class::MOP::is_class_loaded("TestApp::View::Dump"), "loaded ok" );
29 is( $warnings, 0, "no warnings emitted" );
33 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump");
34 is( $warnings, 0, "calling again doesn't reaload" );
36 ok( !Class::MOP::is_class_loaded("TestApp::View::Dump::Request"), "component not yet loaded" );
38 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Request");
39 ok( Class::MOP::is_class_loaded("TestApp::View::Dump::Request"), "loaded ok" );
41 is( $warnings, 0, "calling again doesn't reaload" );
44 eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Probably::Not::There") };
45 ok( $@, "doesn't defatalize" );
46 like( $@, qr/There\.pm.*\@INC/, "error looks right" );
49 eval { Catalyst::Utils::ensure_class_loaded("__PACKAGE__") };
50 ok( $@, "doesn't defatalize" );
51 like( $@, qr/__PACKAGE__\.pm.*\@INC/, "errors sanely on __PACKAGE__.pm" );
54 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Response");
55 is( $@, "foo", '$@ is untouched' );
58 eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Not::In::Inc::But::Does::Exist") };
59 ok( !$@, "no error when loading non existent .pm that *does* have a symbol table entry" );
62 eval { Catalyst::Utils::ensure_class_loaded('Silly::File::.#Name') };
63 like($@, qr/Malformed class Name/, 'errored when attempting to load a file beginning with a .');
66 eval { Catalyst::Utils::ensure_class_loaded('Silly::File::Name.pm') };
67 like($@, qr/Malformed class Name/, 'errored sanely when given a classname ending in .pm');
71 Catalyst::Utils::ensure_class_loaded("NullPackage");
72 is( $warnings, 1, 'Loading a package which defines no symbols warns');
73 is( $@, undef, '$@ still undef' );