add changes for next release
[gitmo/Class-MOP.git] / t / 083_load_class.t
CommitLineData
3f7759c1 1#!/usr/bin/env perl
2use strict;
3use warnings;
b3b7a216 4use Test::More tests => 15;
3f7759c1 5use Test::Exception;
6
7require Class::MOP;
8use lib 't/lib';
9
10ok(!Class::MOP::is_class_loaded(), "is_class_loaded with no argument returns false");
11ok(!Class::MOP::is_class_loaded(''), "can't load the empty class");
12ok(!Class::MOP::is_class_loaded(\"foo"), "can't load a class name reference??");
13
14throws_ok { Class::MOP::load_class() } qr/Invalid class name \(undef\)/;
15throws_ok { Class::MOP::load_class('') } qr/Invalid class name \(\)/;
16throws_ok { Class::MOP::load_class(\"foo") } qr/Invalid class name \(SCALAR\(\w+\)\)/;
b3b7a216 17throws_ok { Class::MOP::load_class('bogus name') } qr/Invalid class name \(bogus name\)/;
3f7759c1 18
07940968 19my $meta = Class::MOP::load_class('BinaryTree');
20ok($meta, "successfully loaded the class BinaryTree");
21is($meta->name, "BinaryTree", "load_class returns the metaclass");
3f7759c1 22can_ok('BinaryTree' => 'traverse');
23
24do {
25 package Class;
26 sub method {}
27};
28
29ok(Class::MOP::load_class('Class'), "this should not die!");
30
31throws_ok {
32 Class::MOP::load_class('FakeClassOhNo');
33} qr/Can't locate /;
34
35throws_ok {
36 Class::MOP::load_class('SyntaxError');
37} qr/Missing right curly/;
38
9e275e86 39{
40 package Other;
41 use constant foo => "bar";
42}
43
b3b7a216 44lives_ok {
45 ok( Class::MOP::is_class_loaded("Other"), 'is_class_loaded(Other)' );
46}
47"a class with just constants is still a class";