Merge branch 'stable'
[gitmo/Class-MOP.git] / t / 200_Class_C3_compatibility.t
CommitLineData
663f8198 1use strict;
2use warnings;
3
86a4d873 4use Test::More;
663f8198 5
6=pod
7
86a4d873 8This tests that Class::MOP works correctly
9with Class::C3 and it's somewhat insane
663f8198 10approach to method resolution.
11
12=cut
13
86a4d873 14use Class::MOP;
663f8198 15
16{
17 package Diamond_A;
77a143ba 18 use mro 'c3';
663f8198 19 use metaclass; # everyone will just inherit this now :)
86a4d873 20
663f8198 21 sub hello { 'Diamond_A::hello' }
22}
23{
24 package Diamond_B;
86a4d873 25 use mro 'c3';
663f8198 26 use base 'Diamond_A';
663f8198 27}
28{
29 package Diamond_C;
77a143ba 30 use mro 'c3';
86a4d873 31 use base 'Diamond_A';
32
663f8198 33 sub hello { 'Diamond_C::hello' }
34}
35{
36 package Diamond_D;
86a4d873 37 use mro 'c3';
663f8198 38 use base ('Diamond_B', 'Diamond_C');
663f8198 39}
40
86a4d873 41# we have to manually initialize
42# Class::C3 since we potentially
663f8198 43# skip this test if it is not present
44Class::C3::initialize();
45
46is_deeply(
77a143ba 47# [ Class::C3::calculateMRO('Diamond_D') ],
48 [ Diamond_D->meta->class_precedence_list ],
663f8198 49 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
50 '... got the right MRO for Diamond_D');
51
52ok(Diamond_A->meta->has_method('hello'), '... A has a method hello');
53ok(!Diamond_B->meta->has_method('hello'), '... B does not have a method hello');
663f8198 54
55ok(Diamond_C->meta->has_method('hello'), '... C has a method hello');
56ok(!Diamond_D->meta->has_method('hello'), '... D does not have a method hello');
21af8dc9 57
58SKIP: {
59 skip "C3 does not make aliases on 5.9.5+", 2 if $] > 5.009_004;
60 ok(defined &Diamond_B::hello, '... B does have an alias to the method hello');
61 ok(defined &Diamond_D::hello, '... D does have an alias to the method hello');
62}
86a4d873 63
64done_testing;