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