add test that requires Moose -- skips if moose is not installed.
[gitmo/Class-MOP.git] / t / 000_load.t
CommitLineData
8b978dd5 1use strict;
2use warnings;
3
bfaf96f4 4use Test::More tests => 49;
8b978dd5 5
6BEGIN {
1a7ebbb3 7 use_ok('Class::MOP');
b5fc2d24 8 use_ok('Class::MOP::Package');
9 use_ok('Class::MOP::Module');
8b978dd5 10 use_ok('Class::MOP::Class');
29d4e92a 11 use_ok('Class::MOP::Class::Immutable::Trait');
8b978dd5 12 use_ok('Class::MOP::Attribute');
b5fc2d24 13 use_ok('Class::MOP::Method');
14 use_ok('Class::MOP::Method::Wrapped');
29d4e92a 15 use_ok('Class::MOP::Method::Inlined');
b5fc2d24 16 use_ok('Class::MOP::Method::Generated');
17 use_ok('Class::MOP::Method::Accessor');
18 use_ok('Class::MOP::Method::Constructor');
19 use_ok('Class::MOP::Instance');
20 use_ok('Class::MOP::Object');
d41e86f2 21}
22
23# make sure we are tracking metaclasses correctly
24
25my %METAS = (
1f833546 26 'Class::MOP::Attribute' => Class::MOP::Attribute->meta,
29d4e92a 27 'Class::MOP::Method::Inlined' => Class::MOP::Method::Inlined->meta,
1f833546 28 'Class::MOP::Method::Generated' => Class::MOP::Method::Generated->meta,
29 'Class::MOP::Method::Accessor' => Class::MOP::Method::Accessor->meta,
30 'Class::MOP::Method::Constructor' =>
31 Class::MOP::Method::Constructor->meta,
32 'Class::MOP::Package' => Class::MOP::Package->meta,
33 'Class::MOP::Module' => Class::MOP::Module->meta,
34 'Class::MOP::Class' => Class::MOP::Class->meta,
35 'Class::MOP::Method' => Class::MOP::Method->meta,
36 'Class::MOP::Method::Wrapped' => Class::MOP::Method::Wrapped->meta,
37 'Class::MOP::Instance' => Class::MOP::Instance->meta,
38 'Class::MOP::Object' => Class::MOP::Object->meta,
f5d08022 39 'Class::MOP::Class::Immutable::Trait' => Class::MOP::Class::Immutable::Trait->meta,
40 'Class::MOP::Class::Immutable::Class::MOP::Class' => Class::MOP::Class::Immutable::Class::MOP::Class->meta,
d41e86f2 41);
42
b5fc2d24 43ok( Class::MOP::is_class_loaded($_), '... ' . $_ . ' is loaded' )
44 for keys %METAS;
448b6e55 45
b5fc2d24 46ok( $_->is_immutable(), '... ' . $_->name . ' is immutable' )
47 for values %METAS;
4d47b77f 48
d41e86f2 49is_deeply(
b5fc2d24 50 {Class::MOP::get_all_metaclasses},
f5d08022 51 \%METAS,
b5fc2d24 52 '... got all the metaclasses'
53);
d41e86f2 54
55is_deeply(
b5fc2d24 56 [
57 sort { $a->name cmp $b->name } Class::MOP::get_all_metaclass_instances
58 ],
59 [
60 Class::MOP::Attribute->meta,
61 Class::MOP::Class->meta,
f5d08022 62 Class::MOP::Class::Immutable::Class::MOP::Class->meta,
63 Class::MOP::Class::Immutable::Trait->meta,
b5fc2d24 64 Class::MOP::Instance->meta,
2243a22b 65 Class::MOP::Method->meta,
d90b42a6 66 Class::MOP::Method::Accessor->meta,
b5fc2d24 67 Class::MOP::Method::Constructor->meta,
68 Class::MOP::Method::Generated->meta,
29d4e92a 69 Class::MOP::Method::Inlined->meta,
b6164407 70 Class::MOP::Method::Wrapped->meta,
b5fc2d24 71 Class::MOP::Module->meta,
72 Class::MOP::Object->meta,
73 Class::MOP::Package->meta,
2243a22b 74 ],
b5fc2d24 75 '... got all the metaclass instances'
76);
d41e86f2 77
78is_deeply(
be7677c7 79 [ sort { $a cmp $b } Class::MOP::get_all_metaclass_names() ],
b5fc2d24 80 [
81 sort qw/
82 Class::MOP::Attribute
83 Class::MOP::Class
f5d08022 84 Class::MOP::Class::Immutable::Class::MOP::Class
85 Class::MOP::Class::Immutable::Trait
b5fc2d24 86 Class::MOP::Instance
87 Class::MOP::Method
88 Class::MOP::Method::Accessor
89 Class::MOP::Method::Constructor
90 Class::MOP::Method::Generated
29d4e92a 91 Class::MOP::Method::Inlined
b5fc2d24 92 Class::MOP::Method::Wrapped
93 Class::MOP::Module
94 Class::MOP::Object
95 Class::MOP::Package
f5d08022 96 /,
b5fc2d24 97 ],
98 '... got all the metaclass names'
99);
100
b5fc2d24 101# testing the meta-circularity of the system
dc76a410 102
b5fc2d24 103is(
104 Class::MOP::Class->meta, Class::MOP::Class->meta->meta,
105 '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta'
106);
dc76a410 107
b5fc2d24 108is(
a7b17d6f 109 Class::MOP::Class->meta->meta, Class::MOP::Class->meta->meta->meta,
110 '... Class::MOP::Class->meta->meta == Class::MOP::Class->meta->meta->meta'
111);
112
113is(
b5fc2d24 114 Class::MOP::Class->meta, Class::MOP::Class->meta->meta->meta,
115 '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta->meta'
116);
dc76a410 117
b5fc2d24 118is(
119 Class::MOP::Class->meta, Class::MOP::Class->meta->meta->meta->meta,
120 '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta->meta->meta'
121);
dc76a410 122