avoid needing . in @INC in dev mode
[gitmo/Algorithm-C3.git] / t / 001_merge.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7
8 BEGIN {
9     use_ok('Algorithm::C3');          
10 }
11
12 {
13     package My::A;
14     package My::C;
15     our @ISA = ('My::A');
16     package My::B;
17     our @ISA = ('My::A');    
18     package My::D;       
19     our @ISA = ('My::B', 'My::C');         
20 }
21
22 {
23     my @merged = Algorithm::C3::merge(
24         'My::D',
25         sub {
26             no strict 'refs';
27             @{$_[0] . '::ISA'};
28         }
29     );
30             
31     is_deeply(
32         \@merged,
33         [ qw/My::D My::B My::C My::A/ ],
34         '... merged the lists correctly');
35 }
36
37 {
38     package My::E;
39     
40     sub supers {
41         no strict 'refs';
42         @{$_[0] . '::ISA'};
43     }    
44     
45     package My::F;
46     our @ISA = ('My::E');
47     package My::G;
48     our @ISA = ('My::E');    
49     package My::H;       
50     our @ISA = ('My::G', 'My::F');
51     sub method_exists_only_in_H { @ISA }
52 }
53
54 {
55     my @merged = Algorithm::C3::merge('My::H', 'supers');
56
57     is_deeply(
58         \@merged,
59         [ qw/My::H My::G My::F My::E/ ],
60         '... merged the lists correctly');    
61 }
62
63 eval {
64     Algorithm::C3::merge(
65         'My::H',
66         'this_method_does_not_exist'
67     );
68 };
69 ok($@, '... this died as we expected');
70
71 eval {
72     Algorithm::C3::merge(
73         'My::H',
74         'method_exists_only_in_H'
75     );
76 };
77 ok($@, '... this died as we expected');