5 use Class::Load 'is_class_loaded';
9 if ($^O =~ m/^MSWin/) {
10 plan skip_all => 'Skipping this test on Windows until someone with Windows has time to fix it';
13 use_ok("Catalyst::Utils");
17 package This::Module::Is::Not::In::Inc::But::Does::Exist;
22 $SIG{__WARN__} = sub {
23 return if $_[0] =~ /Subroutine (?:un|re|)initialize redefined at .*C3\.pm/;
27 ok( !is_class_loaded("TestApp::View::Dump"), "component not yet loaded" );
29 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump");
31 ok( is_class_loaded("TestApp::View::Dump"), "loaded ok" );
32 is( $warnings, 0, "no warnings emitted" );
36 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump");
37 is( $warnings, 0, "calling again doesn't reaload" );
39 ok( !is_class_loaded("TestApp::View::Dump::Request"), "component not yet loaded" );
41 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Request");
42 ok( is_class_loaded("TestApp::View::Dump::Request"), "loaded ok" );
44 is( $warnings, 0, "calling again doesn't reaload" );
47 eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Probably::Not::There") };
48 ok( $@, "doesn't defatalize" );
49 like( $@, qr/There\.pm.*\@INC/, "error looks right" );
52 eval { Catalyst::Utils::ensure_class_loaded("__PACKAGE__") };
53 ok( $@, "doesn't defatalize" );
54 like( $@, qr/__PACKAGE__\.pm.*\@INC/, "errors sanely on __PACKAGE__.pm" );
57 Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Response");
58 is( $@, "foo", '$@ is untouched' );
61 eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Not::In::Inc::But::Does::Exist") };
62 ok( !$@, "no error when loading non existent .pm that *does* have a symbol table entry" );
65 eval { Catalyst::Utils::ensure_class_loaded('Silly::File::.#Name') };
66 like($@, qr/Malformed class Name/, 'errored when attempting to load a file beginning with a .');
69 eval { Catalyst::Utils::ensure_class_loaded('Silly::File::Name.pm') };
70 like($@, qr/Malformed class Name/, 'errored sanely when given a classname ending in .pm');
74 Catalyst::Utils::ensure_class_loaded("NullPackage");
75 is( $warnings, 1, 'Loading a package which defines no symbols warns');
76 is( $@, undef, '$@ still undef' );