Instead of loading by path, we let Perl do its thing and load by
[gitmo/Class-MOP.git] / t / 083_load_class.t
CommitLineData
3f7759c1 1#!/usr/bin/env perl
2use strict;
3use warnings;
07940968 4use Test::More tests => 14;
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+\)\)/;
17
07940968 18my $meta = Class::MOP::load_class('BinaryTree');
19ok($meta, "successfully loaded the class BinaryTree");
20is($meta->name, "BinaryTree", "load_class returns the metaclass");
3f7759c1 21can_ok('BinaryTree' => 'traverse');
22
23do {
24 package Class;
25 sub method {}
26};
27
28ok(Class::MOP::load_class('Class'), "this should not die!");
29
30throws_ok {
31 Class::MOP::load_class('FakeClassOhNo');
32} qr/Can't locate /;
33
34throws_ok {
35 Class::MOP::load_class('SyntaxError');
36} qr/Missing right curly/;
37
9e275e86 38{
39 package Other;
40 use constant foo => "bar";
41}
42
43lives_ok { ok(Class::MOP::is_class_loaded("Other")) } "a class with just constants is still a class";