Add test for load_class on stashes with GVs without actual methods.
[gitmo/Class-MOP.git] / t / 001_basic.t
CommitLineData
8b978dd5 1use strict;
2use warnings;
3
efd3d14c 4use Test::More tests => 23;
0882828e 5use Test::Exception;
8b978dd5 6
efd3d14c 7use Class::MOP;
8use Class::MOP::Class;
8b978dd5 9
10{
11 package Foo;
aa448b16 12 use metaclass;
8b978dd5 13 our $VERSION = '0.01';
14
15 package Bar;
16 our @ISA = ('Foo');
88dd563c 17
18 our $AUTHORITY = 'cpan:JRANDOM';
8b978dd5 19}
20
aa448b16 21my $Foo = Foo->meta;
8b978dd5 22isa_ok($Foo, 'Class::MOP::Class');
23
aa448b16 24my $Bar = Bar->meta;
8b978dd5 25isa_ok($Bar, 'Class::MOP::Class');
26
27is($Foo->name, 'Foo', '... Foo->name == Foo');
28is($Bar->name, 'Bar', '... Bar->name == Bar');
29
30is($Foo->version, '0.01', '... Foo->version == 0.01');
31is($Bar->version, undef, '... Bar->version == undef');
32
88dd563c 33is($Foo->authority, undef, '... Foo->authority == undef');
34is($Bar->authority, 'cpan:JRANDOM', '... Bar->authority == cpan:JRANDOM');
35
36is($Foo->identifier, 'Foo-0.01', '... Foo->identifier == Foo-0.01');
37is($Bar->identifier, 'Bar-cpan:JRANDOM', '... Bar->identifier == Bar-cpan:JRANDOM');
38
8b978dd5 39is_deeply([$Foo->superclasses], [], '... Foo has no superclasses');
40is_deeply([$Bar->superclasses], ['Foo'], '... Bar->superclasses == (Foo)');
41
42$Foo->superclasses('UNIVERSAL');
43
44is_deeply([$Foo->superclasses], ['UNIVERSAL'], '... Foo->superclasses == (UNIVERSAL) now');
45
46is_deeply(
47 [ $Foo->class_precedence_list ],
48 [ 'Foo', 'UNIVERSAL' ],
49 '... Foo->class_precedence_list == (Foo, UNIVERSAL)');
50
51is_deeply(
52 [ $Bar->class_precedence_list ],
53 [ 'Bar', 'Foo', 'UNIVERSAL' ],
54 '... Bar->class_precedence_list == (Bar, Foo, UNIVERSAL)');
55
56# create a class using Class::MOP::Class ...
57
58my $Baz = Class::MOP::Class->create(
88dd563c 59 'Baz' => (
60 version => '0.10',
61 authority => 'cpan:YOMAMA',
8b978dd5 62 superclasses => [ 'Bar' ]
63 ));
64isa_ok($Baz, 'Class::MOP::Class');
aa448b16 65is(Baz->meta, $Baz, '... our metaclasses are singletons');
8b978dd5 66
67is($Baz->name, 'Baz', '... Baz->name == Baz');
68is($Baz->version, '0.10', '... Baz->version == 0.10');
88dd563c 69is($Baz->authority, 'cpan:YOMAMA', '... Baz->authority == YOMAMA');
70
71is($Baz->identifier, 'Baz-0.10-cpan:YOMAMA', '... Baz->identifier == Baz-0.10-cpan:YOMAMA');
8b978dd5 72
73is_deeply([$Baz->superclasses], ['Bar'], '... Baz->superclasses == (Bar)');
74
75is_deeply(
76 [ $Baz->class_precedence_list ],
77 [ 'Baz', 'Bar', 'Foo', 'UNIVERSAL' ],
78 '... Baz->class_precedence_list == (Baz, Bar, Foo, UNIVERSAL)');
d41e86f2 79