X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F083_load_class.t;h=e93c427f1e4df0b668571f8a523a6ac9d884bdde;hb=fbedcfb3e98c797922bad3788f9b08063cafebcf;hp=06ff0c14b9aede22e403177970131810fbc73137;hpb=063ad0c5732b1431b6b0cfdba6c99deb66f1b9cf;p=gitmo%2FClass-MOP.git diff --git a/t/083_load_class.t b/t/083_load_class.t index 06ff0c1..e93c427 100644 --- a/t/083_load_class.t +++ b/t/083_load_class.t @@ -1,7 +1,6 @@ -#!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 27; +use Test::More tests => 33; use Test::Exception; require Class::MOP; @@ -43,11 +42,19 @@ ok( !Class::MOP::does_metaclass_exist("Class"), "no metaclass for non MOP class" throws_ok { Class::MOP::load_class('FakeClassOhNo'); -} qr/Can't locate /; +} +qr/Can't locate /; throws_ok { Class::MOP::load_class('SyntaxError'); -} qr/Missing right curly/; +} +qr/Missing right curly/; + +throws_ok { + Class::MOP::load_class('This::Does::Not::Exist'); +} +qr/Could not load class \(This::Does::Not::Exist\) because :/, + 'Many Moose tests rely on the exact formatting of this error'; { package Other; @@ -67,11 +74,43 @@ lives_ok { isa_ok( Class::MOP::load_class("Lala"), "Class::MOP::Class", "when an object has a metaclass it is returned" ); lives_ok { - isa_ok(Class::MOP::load_first_existing_class("Lala", "Does::Not::Exist"), "Class::MOP::Class", 'Load_classes first param ok, metaclass returned'); - isa_ok(Class::MOP::load_first_existing_class("Does::Not::Exist", "Lala"), "Class::MOP::Class", 'Load_classes second param ok, metaclass returned'); + is(Class::MOP::load_first_existing_class("Lala", "Does::Not::Exist"), "Lala", 'load_first_existing_class 1/2 params ok, class name returned'); + is(Class::MOP::load_first_existing_class("Does::Not::Exist", "Lala"), "Lala", 'load_first_existing_class 2/2 params ok, class name returned'); } 'load_classes works'; + throws_ok { Class::MOP::load_first_existing_class("Does::Not::Exist", "Also::Does::Not::Exist") } qr/Could not load class \(Does::Not::Exist.*Could not load class \(Also::Does::Not::Exist/s, 'Multiple non-existant classes cause exception'; +{ + sub whatever { + TestClassLoaded::this_method_does_not_even_exist(); + } + + ok( ! Class::MOP::is_class_loaded('TestClassLoaded'), + 'the mere mention of TestClassLoaded in the whatever sub does not make us think it has been loaded' ); +} + +{ + require TestClassLoaded::Sub; + ok( ! Class::MOP::is_class_loaded('TestClassLoaded'), + 'requiring TestClassLoaded::Sub does not make us think TestClassLoaded is loaded' ); +} + +{ + require TestClassLoaded; + ok( Class::MOP::is_class_loaded('TestClassLoaded'), + 'We see that TestClassLoaded is loaded after requiring it (it has methods but no $VERSION or @ISA)' ); +} +{ + require TestClassLoaded2; + ok( Class::MOP::is_class_loaded('TestClassLoaded2'), + 'We see that TestClassLoaded2 is loaded after requiring it (it has a $VERSION but no methods or @ISA)' ); +} + +{ + require TestClassLoaded3; + ok( Class::MOP::is_class_loaded('TestClassLoaded3'), + 'We see that TestClassLoaded3 is loaded after requiring it (it has an @ISA but no methods or $VERSION)' ); +}