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