3 use Test::More tests => 32;
9 ok(!Class::MOP::is_class_loaded(), "is_class_loaded with no argument returns false");
10 ok(!Class::MOP::is_class_loaded(''), "can't load the empty class");
11 ok(!Class::MOP::is_class_loaded(\"foo"), "can't load a class name reference??");
13 ok(!Class::MOP::_is_valid_class_name(undef), 'undef is not a valid class name');
14 ok(!Class::MOP::_is_valid_class_name(''), 'empty string is not a valid class name');
15 ok(!Class::MOP::_is_valid_class_name(\"foo"), 'a reference is not a valid class name');
16 ok(!Class::MOP::_is_valid_class_name('bogus name'), q{'bogus name' is not a valid class name});
17 ok(Class::MOP::_is_valid_class_name('Foo'), q{'Foo' is a valid class name});
18 ok(Class::MOP::_is_valid_class_name('Foo::Bar'), q{'Foo::Bar' is a valid class name});
19 ok(Class::MOP::_is_valid_class_name('Foo_::Bar2'), q{'Foo_::Bar2' is a valid class name});
20 throws_ok { Class::MOP::load_class('bogus name') } qr/Invalid class name \(bogus name\)/;
23 Class::MOP::load_class('__PACKAGE__')
24 } qr/__PACKAGE__\.pm.*\@INC/, 'errors sanely on __PACKAGE__.pm';
26 Class::MOP::load_class('BinaryTree');
27 can_ok('BinaryTree' => 'traverse');
37 eval { Class::MOP::load_class('Class') };
38 ok( ! $@, 'load_class does not die if the package is already defined' );
41 ok( !Class::MOP::does_metaclass_exist("Class"), "no metaclass for non MOP class" );
44 Class::MOP::load_class('FakeClassOhNo');
49 Class::MOP::load_class('SyntaxError');
51 qr/Missing right curly/;
54 delete $INC{'SyntaxError.pm'};
55 Class::MOP::load_first_existing_class(
56 'FakeClassOhNo', 'SyntaxError', 'Class'
59 qr/Missing right curly/,
60 'load_first_existing_class does not pass over an existing (bad) module';
63 Class::MOP::load_class('This::Does::Not::Exist');
65 qr/Could not load class \(This::Does::Not::Exist\) because :/,
66 'Many Moose tests rely on the exact formatting of this error';
70 use constant foo => "bar";
74 ok(Class::MOP::is_class_loaded("Other"), 'is_class_loaded(Other)');
76 "a class with just constants is still a class";
84 is(Class::MOP::load_first_existing_class("Lala", "Does::Not::Exist"), "Lala", 'load_first_existing_class 1/2 params ok, class name returned');
85 is(Class::MOP::load_first_existing_class("Does::Not::Exist", "Lala"), "Lala", 'load_first_existing_class 2/2 params ok, class name returned');
86 } 'load_classes works';
89 Class::MOP::load_first_existing_class("Does::Not::Exist", "Also::Does::Not::Exist")
90 } qr/Could not load class \(Does::Not::Exist.*Could not load class \(Also::Does::Not::Exist/s, 'Multiple non-existant classes cause exception';
94 TestClassLoaded::this_method_does_not_even_exist();
97 ok( ! Class::MOP::is_class_loaded('TestClassLoaded'),
98 'the mere mention of TestClassLoaded in the whatever sub does not make us think it has been loaded' );
102 require TestClassLoaded::Sub;
103 ok( ! Class::MOP::is_class_loaded('TestClassLoaded'),
104 'requiring TestClassLoaded::Sub does not make us think TestClassLoaded is loaded' );
108 require TestClassLoaded;
109 ok( Class::MOP::is_class_loaded('TestClassLoaded'),
110 'We see that TestClassLoaded is loaded after requiring it (it has methods but no $VERSION or @ISA)' );
114 require TestClassLoaded2;
115 ok( Class::MOP::is_class_loaded('TestClassLoaded2'),
116 'We see that TestClassLoaded2 is loaded after requiring it (it has a $VERSION but no methods or @ISA)' );
120 require TestClassLoaded3;
121 ok( Class::MOP::is_class_loaded('TestClassLoaded3'),
122 'We see that TestClassLoaded3 is loaded after requiring it (it has an @ISA but no methods or $VERSION)' );
131 ok( ! Class::MOP::is_class_loaded('Not::Loaded'),
132 'the mere existence of an @ISA for a package does not mean a class is loaded' );
141 ok( Class::MOP::is_class_loaded('Loaded::Ish'),
142 'an @ISA with members does mean a class is loaded' );