Expand the c3 mro test from d009cb7d
[dbsrgits/DBIx-Class.git] / xt / extra / c3_mro.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
e8b77df6 3use warnings;
e4c24739 4use strict;
e8b77df6 5
6use Test::More;
d009cb7d 7use DBICTest;
5e0eea35 8use DBIx::Class::Optional::Dependencies;
d009cb7d 9
10my @global_ISA_tail = qw(
11 DBIx::Class
12 DBIx::Class::Componentised
13 Class::C3::Componentised
14 DBIx::Class::AccessorGroup
15 Class::Accessor::Grouped
16);
e4c24739 17
d009cb7d 18is(
983f766d 19 mro::get_mro($_),
d009cb7d 20 'c3',
983f766d 21 "Correct mro on base class '$_'",
22) for grep { $_ =~ /^DBIx::Class/ } @global_ISA_tail;
d8190011 23
e4c24739 24{
e8b77df6 25 package AAA;
e4c24739 26
e8b77df6 27 use base "DBIx::Class::Core";
28}
e4c24739 29
e8b77df6 30{
31 package BBB;
e4c24739 32
e8b77df6 33 use base 'AAA';
e4c24739 34
e8b77df6 35 #Injecting a direct parent.
36 __PACKAGE__->inject_base( __PACKAGE__, 'AAA' );
37}
e4c24739 38
e8b77df6 39{
40 package CCC;
e4c24739 41
e8b77df6 42 use base 'AAA';
e4c24739 43
e8b77df6 44 #Injecting an indirect parent.
45 __PACKAGE__->inject_base( __PACKAGE__, 'DBIx::Class::Core' );
e4c24739 46}
47
4f507947 48eval { mro::get_linear_isa('BBB'); };
e4c24739 49ok (! $@, "Correctly skipped injecting a direct parent of class BBB");
50
4f507947 51eval { mro::get_linear_isa('CCC'); };
e4c24739 52ok (! $@, "Correctly skipped injecting an indirect parent of class BBB");
e8b77df6 53
d009cb7d 54
55my $art = DBICTest->init_schema->resultset("Artist")->next;
56
57check_ancestry($_) for (
58 ref( $art ),
59 ref( $art->result_source ),
60 ref( $art->result_source->resultset ),
61 ref( $art->result_source->schema ),
7f068248 62 ( map
63 { ref $art->result_source->schema->source($_) }
64 $art->result_source->schema->sources
65 ),
d009cb7d 66 qw( AAA BBB CCC ),
5e0eea35 67 ((! DBIx::Class::Optional::Dependencies->req_ok_for('cdbicompat') ) ? () : do {
68 unshift @INC, 't/cdbi/testlib';
69 map { eval "require $_" or die $@; $_ } qw(
70 Film Lazy Actor ActorAlias ImplicitInflate
71 );
72 }),
d009cb7d 73);
74
e8b77df6 75use DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server;
e8b77df6 76
77is_deeply (
78 mro::get_linear_isa('DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server'),
79 [qw/
80 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server
81 DBIx::Class::Storage::DBI::Sybase
82 DBIx::Class::Storage::DBI::MSSQL
83 DBIx::Class::Storage::DBI::UniqueIdentifier
fabbd5cc 84 DBIx::Class::Storage::DBI::IdentityInsert
e8b77df6 85 DBIx::Class::Storage::DBI
86 DBIx::Class::Storage::DBIHacks
87 DBIx::Class::Storage
d009cb7d 88 /, @global_ISA_tail],
e8b77df6 89 'Correctly ordered ISA of DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server'
90);
91
87bf71d5 92my $storage = DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server->new;
c1e5a9ac 93$storage->connect_info(['dbi:SQLite::memory:']); # determine_driver's init() connects for this subclass
87bf71d5 94$storage->_determine_driver;
e8b77df6 95is (
87bf71d5 96 $storage->can('sql_limit_dialect'),
97 'DBIx::Class::Storage::DBI::MSSQL'->can('sql_limit_dialect'),
e8b77df6 98 'Correct method picked'
99);
100
750a4ad2 101if ( "$]" >= 5.010 ) {
87bf71d5 102 ok (! $INC{'Class/C3.pm'}, 'No Class::C3 loaded on perl 5.10+');
103
104 # Class::C3::Componentised loads MRO::Compat unconditionally to satisfy
105 # the assumption that once Class::C3::X is loaded, so is Class::C3
106 #ok (! $INC{'MRO/Compat.pm'}, 'No MRO::Compat loaded on perl 5.10+');
107}
108
d009cb7d 109sub check_ancestry {
110 my $class = shift;
111
112 die "Expecting classname" if length ref $class;
113
114 my @linear_ISA = @{ mro::get_linear_isa($class) };
115
116 # something is *VERY* wrong, the splice below won't make it
117 unless (@linear_ISA > @global_ISA_tail) {
118 fail(
119 "Unexpectedly shallow \@ISA for class '$class': "
120 . join ', ', map { "'$_'" } @linear_ISA
121 );
122 return;
123 }
124
125 is_deeply (
126 [ splice @linear_ISA, ($#linear_ISA - $#global_ISA_tail) ],
127 \@global_ISA_tail,
128 "Correct end of \@ISA for '$class'"
129 );
130
131 # check the remainder
132 for my $c (@linear_ISA) {
133 # nothing to see there
134 next if $c =~ /^DBICTest::/;
135
136 next if mro::get_mro($c) eq 'c3';
137
138 fail( "Incorrect mro '@{[ mro::get_mro($c) ]}' on '$c' (parent of '$class')" );
139 }
140}
141
e8b77df6 142done_testing;