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