X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Funit_utils_load_class.t;h=881b1ffd4f338321270553dc6da3c334b4658357;hp=cddc400bb75fe7806fa0b18be05e423ab243ee78;hb=gsoc_breadboard;hpb=d9183506af8ce9cd1339fceb19d941f293efb17b diff --git a/t/unit_utils_load_class.t b/t/unit_utils_load_class.t index cddc400..881b1ff 100644 --- a/t/unit_utils_load_class.t +++ b/t/unit_utils_load_class.t @@ -3,7 +3,8 @@ use strict; use warnings; -use Test::More tests => 12; +use Test::More tests => 18; +use Class::MOP; use lib "t/lib"; @@ -15,13 +16,16 @@ BEGIN { use_ok("Catalyst::Utils") }; } my $warnings = 0; -$SIG{__WARN__} = sub { $warnings++ }; +$SIG{__WARN__} = sub { + return if $_[0] =~ /Subroutine (?:un|re|)initialize redefined at .*C3\.pm/; + $warnings++; +}; -ok( !Class::Inspector->loaded("TestApp::View::Dump"), "component not yet loaded" ); +ok( !Class::MOP::is_class_loaded("TestApp::View::Dump"), "component not yet loaded" ); Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump"); -ok( Class::Inspector->loaded("TestApp::View::Dump"), "loaded ok" ); +ok( Class::MOP::is_class_loaded("TestApp::View::Dump"), "loaded ok" ); is( $warnings, 0, "no warnings emitted" ); $warnings = 0; @@ -29,10 +33,10 @@ $warnings = 0; Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump"); is( $warnings, 0, "calling again doesn't reaload" ); -ok( !Class::Inspector->loaded("TestApp::View::Dump::Request"), "component not yet loaded" ); +ok( !Class::MOP::is_class_loaded("TestApp::View::Dump::Request"), "component not yet loaded" ); Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Request"); -ok( Class::Inspector->loaded("TestApp::View::Dump::Request"), "loaded ok" ); +ok( Class::MOP::is_class_loaded("TestApp::View::Dump::Request"), "loaded ok" ); is( $warnings, 0, "calling again doesn't reaload" ); @@ -41,6 +45,11 @@ eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Probably::Not::Th ok( $@, "doesn't defatalize" ); like( $@, qr/There\.pm.*\@INC/, "error looks right" ); +undef $@; +eval { Catalyst::Utils::ensure_class_loaded("__PACKAGE__") }; +ok( $@, "doesn't defatalize" ); +like( $@, qr/__PACKAGE__\.pm.*\@INC/, "errors sanely on __PACKAGE__.pm" ); + $@ = "foo"; Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Response"); is( $@, "foo", '$@ is untouched' ); @@ -49,3 +58,17 @@ undef $@; eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Not::In::Inc::But::Does::Exist") }; ok( !$@, "no error when loading non existent .pm that *does* have a symbol table entry" ); +undef $@; +eval { Catalyst::Utils::ensure_class_loaded('Silly::File::.#Name') }; +like($@, qr/Malformed class Name/, 'errored when attempting to load a file beginning with a .'); + +undef $@; +eval { Catalyst::Utils::ensure_class_loaded('Silly::File::Name.pm') }; +like($@, qr/Malformed class Name/, 'errored sanely when given a classname ending in .pm'); + +undef $@; +$warnings = 0; +Catalyst::Utils::ensure_class_loaded("NullPackage"); +is( $warnings, 1, 'Loading a package which defines no symbols warns'); +is( $@, undef, '$@ still undef' ); +