Commit | Line | Data |
c052f3dd |
1 | my ($inc_before, $inc_after); |
be68095d |
2 | BEGIN { |
c052f3dd |
3 | $inc_before = [ keys %INC ]; |
4 | require DBIx::Class::Optional::Dependencies; |
5 | $inc_after = [ keys %INC ]; |
be68095d |
6 | } |
7 | |
cb551b07 |
8 | use strict; |
9 | use warnings; |
10 | no warnings qw/once/; |
11 | |
c052f3dd |
12 | use Test::More; |
13 | use Test::Exception; |
e3a7746c |
14 | |
15 | # load before we break require() |
16 | use Scalar::Util(); |
17 | use MRO::Compat(); |
cb551b07 |
18 | use Carp 'confess'; |
d1f653cf |
19 | use List::Util 'shuffle'; |
05c0614b |
20 | |
1888e80f |
21 | SKIP: { |
22 | skip 'Lean load pattern testing unsafe with $ENV{PERL5OPT}', 1 if $ENV{PERL5OPT}; |
23 | skip 'Lean load pattern testing useless with $ENV{RELEASE_TESTING}', 1 if $ENV{RELEASE_TESTING}; |
24 | is_deeply |
25 | $inc_before, |
26 | [], |
27 | 'Nothing was loaded before inc-test' |
28 | ; |
29 | is_deeply |
30 | $inc_after, |
31 | [ 'DBIx/Class/Optional/Dependencies.pm' ], |
32 | 'Nothing was loaded other than DBIx::Class::OptDeps' |
33 | ; |
34 | } |
3c3e76bd |
35 | |
31c31b8d |
36 | # check the project-local groups for sanity |
37 | lives_ok { |
38 | DBIx::Class::Optional::Dependencies->req_group_list |
39 | } "The entire optdep list is well formed"; |
40 | |
05c0614b |
41 | is_deeply ( |
31c31b8d |
42 | [ keys %{ DBIx::Class::Optional::Dependencies->req_list_for ('deploy') } ], |
05c0614b |
43 | [ 'SQL::Translator' ], |
44 | 'Correct deploy() dependency list', |
45 | ); |
46 | |
31c31b8d |
47 | # scope to break require() |
d8799bab |
48 | { |
31c31b8d |
49 | |
50 | # make module loading impossible, regardless of actual libpath contents |
250d9e55 |
51 | local @INC; |
d8799bab |
52 | |
31c31b8d |
53 | # basic test using the deploy target |
54 | for ('deploy', ['deploy']) { |
55 | |
56 | # explicitly blow up cache |
57 | %DBIx::Class::Optional::Dependencies::req_unavailability_cache = (); |
58 | |
59 | ok ( |
60 | ! DBIx::Class::Optional::Dependencies->req_ok_for ($_), |
61 | 'deploy() deps missing', |
62 | ); |
63 | |
64 | like ( |
e3a7746c |
65 | DBIx::Class::Optional::Dependencies->modreq_missing_for ($_), |
66 | qr/ |
67 | \A |
d66442d3 |
68 | SQL::Translator \~ [\d\.]+ |
e3a7746c |
69 | \z |
70 | /x, |
71 | 'expected modreq missing string contents', |
72 | ); |
73 | |
74 | like ( |
31c31b8d |
75 | DBIx::Class::Optional::Dependencies->req_missing_for ($_), |
76 | qr/ |
e3a7746c |
77 | \A |
d66442d3 |
78 | SQL::Translator \~ [\d\.]+ |
e3a7746c |
79 | \Q (see DBIx::Class::Optional::Dependencies documentation for details)\E |
31c31b8d |
80 | \z |
81 | /x, |
82 | 'expected missing string contents', |
83 | ); |
84 | |
85 | like ( |
5ffa39c7 |
86 | DBIx::Class::Optional::Dependencies->modreq_errorlist_for ($_)->{'SQL::Translator'}, |
250d9e55 |
87 | qr|\QCan't locate SQL/Translator.pm|, |
88 | 'correct "unable to locate" exception found in errorlist', |
31c31b8d |
89 | ); |
90 | |
91 | #make it so module appears loaded |
92 | local $INC{'SQL/Translator.pm'} = 1; |
93 | local $SQL::Translator::VERSION = 999; |
94 | |
95 | ok ( |
96 | ! DBIx::Class::Optional::Dependencies->req_ok_for ($_), |
97 | 'deploy() deps missing cached properly from previous run', |
98 | ); |
99 | |
100 | # blow cache again |
101 | %DBIx::Class::Optional::Dependencies::req_unavailability_cache = (); |
102 | |
103 | ok ( |
104 | DBIx::Class::Optional::Dependencies->req_ok_for ($_), |
105 | 'deploy() deps present', |
106 | ); |
107 | |
108 | is ( |
109 | DBIx::Class::Optional::Dependencies->req_missing_for ($_), |
110 | '', |
111 | 'expected null missing string', |
112 | ); |
113 | |
114 | is_deeply ( |
5ffa39c7 |
115 | # use the deprecated method name |
31c31b8d |
116 | DBIx::Class::Optional::Dependencies->req_errorlist_for ($_), |
117 | undef, |
118 | 'expected empty errorlist', |
119 | ); |
120 | } |
121 | |
e3a7746c |
122 | # test single-db text |
123 | local $ENV{DBICTEST_MYSQL_DSN}; |
124 | is_deeply( |
125 | DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_mysql'), |
126 | undef, |
127 | 'unknown optional dependencies list for testing MySQL without ENV var', |
128 | ); |
31c31b8d |
129 | is_deeply( |
e3a7746c |
130 | DBIx::Class::Optional::Dependencies->modreq_list_for('test_rdbms_mysql'), |
131 | { 'DBD::mysql' => 0 }, |
132 | 'correct optional module dependencies list for testing MySQL without ENV var', |
133 | ); |
134 | |
135 | local $ENV{DBICTEST_MYSQL_DSN}; |
136 | local $ENV{DBICTEST_PG_DSN}; |
137 | |
2baba3d9 |
138 | # regular |
e3a7746c |
139 | is_deeply( |
140 | DBIx::Class::Optional::Dependencies->modreq_list_for('test_rdbms_pg'), |
141 | { 'DBD::Pg' => '2.009002' }, |
142 | 'optional dependencies list for testing Postgres without envvar', |
143 | ); |
144 | |
145 | is_deeply( |
146 | DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_pg'), |
147 | undef, |
148 | 'optional dependencies list for testing Postgres without envvar', |
d8799bab |
149 | ); |
150 | |
31c31b8d |
151 | is_deeply( |
152 | DBIx::Class::Optional::Dependencies->req_list_for('rdbms_pg'), |
153 | { 'DBD::Pg' => '0', }, |
154 | 'optional dependencies list for using Postgres matches', |
d8799bab |
155 | ); |
156 | |
d1f653cf |
157 | is_deeply( |
158 | DBIx::Class::Optional::Dependencies->req_missing_for('rdbms_pg'), |
159 | 'DBD::Pg (see DBIx::Class::Optional::Dependencies documentation for details)', |
160 | 'optional dependencies missing list for using Postgres matches', |
161 | ); |
162 | |
e3a7746c |
163 | # test combination of different requirements on same module (pg's are relatively stable) |
31c31b8d |
164 | is_deeply ( |
d1f653cf |
165 | DBIx::Class::Optional::Dependencies->req_list_for([shuffle qw( rdbms_pg test_rdbms_pg )]), |
e3a7746c |
166 | { 'DBD::Pg' => '0' }, |
167 | 'optional module dependencies list for testing Postgres matches without envvar', |
168 | ); |
169 | |
170 | is( |
171 | DBIx::Class::Optional::Dependencies->req_missing_for([qw( rdbms_pg test_rdbms_pg )]), |
d66442d3 |
172 | 'DBD::Pg~2.009002 as well as the following group(s) of environment variables: DBICTEST_PG_DSN/..._USER/..._PASS', |
e3a7746c |
173 | 'optional dependencies for testing Postgres without envvar' |
174 | ); |
175 | |
176 | is( |
d1f653cf |
177 | DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( test_rdbms_mysql test_rdbms_pg )]), |
d66442d3 |
178 | 'DBD::mysql DBD::Pg~2.009002 as well as the following group(s) of environment variables: DBICTEST_MYSQL_DSN/..._USER/..._PASS and DBICTEST_PG_DSN/..._USER/..._PASS', |
e3a7746c |
179 | 'optional dependencies for testing Postgres+MySQL without envvars' |
180 | ); |
181 | |
182 | $ENV{DBICTEST_PG_DSN} = 'boo'; |
183 | is_deeply ( |
d1f653cf |
184 | DBIx::Class::Optional::Dependencies->modreq_list_for([shuffle qw( rdbms_pg test_rdbms_pg )]), |
31c31b8d |
185 | { 'DBD::Pg' => '2.009002' }, |
e3a7746c |
186 | 'optional module dependencies list for testing Postgres matches with envvar', |
d8799bab |
187 | ); |
05c0614b |
188 | |
31c31b8d |
189 | is( |
d1f653cf |
190 | DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( rdbms_pg test_rdbms_pg )]), |
d66442d3 |
191 | 'DBD::Pg~2.009002', |
e3a7746c |
192 | 'optional dependencies error text for testing Postgres matches with evvar', |
31c31b8d |
193 | ); |
05c0614b |
194 | |
2baba3d9 |
195 | # ICDT augmentation |
196 | my $mysql_icdt = [shuffle qw( test_rdbms_mysql icdt )]; |
197 | |
198 | is_deeply( |
199 | DBIx::Class::Optional::Dependencies->modreq_list_for($mysql_icdt), |
200 | { |
201 | 'DateTime' => '0.55', |
202 | 'DBD::mysql' => 0, |
203 | 'DateTime::Format::MySQL' => 0, |
204 | }, |
205 | 'optional module dependencies list for testing ICDT MySQL without envvar', |
206 | ); |
207 | |
208 | is_deeply( |
209 | DBIx::Class::Optional::Dependencies->req_list_for($mysql_icdt), |
210 | { |
211 | 'DateTime' => '0.55', |
212 | }, |
213 | 'optional dependencies list for testing ICDT MySQL without envvar', |
214 | ); |
215 | |
216 | is( |
217 | DBIx::Class::Optional::Dependencies->req_missing_for($mysql_icdt), |
d66442d3 |
218 | 'DateTime~0.55 DateTime::Format::MySQL DBD::mysql as well as the following group(s) of environment variables: DBICTEST_MYSQL_DSN/..._USER/..._PASS', |
2baba3d9 |
219 | 'missing optional dependencies for testing ICDT MySQL without envvars' |
220 | ); |
221 | |
d1f653cf |
222 | # test multi-level include with a variable and mandatory part converging on same included dep |
223 | local $ENV{DBICTEST_MSACCESS_ODBC_DSN}; |
224 | local $ENV{DBICTEST_MSSQL_ODBC_DSN} = 'foo'; |
2baba3d9 |
225 | my $msaccess_mssql_icdt = [ shuffle qw( test_rdbms_msaccess_odbc test_rdbms_mssql_odbc icdt ) ]; |
d1f653cf |
226 | is_deeply( |
2baba3d9 |
227 | DBIx::Class::Optional::Dependencies->req_missing_for($msaccess_mssql_icdt), |
d66442d3 |
228 | 'Data::GUID DateTime~0.55 DateTime::Format::Strptime~1.2 DBD::ODBC as well as the following group(s) of environment variables: DBICTEST_MSACCESS_ODBC_DSN/..._USER/..._PASS', |
d1f653cf |
229 | 'Correct req_missing_for on multi-level converging include', |
230 | ); |
231 | |
232 | is_deeply( |
2baba3d9 |
233 | DBIx::Class::Optional::Dependencies->modreq_missing_for($msaccess_mssql_icdt), |
d66442d3 |
234 | 'Data::GUID DateTime~0.55 DateTime::Format::Strptime~1.2 DBD::ODBC', |
d1f653cf |
235 | 'Correct modreq_missing_for on multi-level converging include', |
236 | ); |
237 | |
238 | is_deeply( |
2baba3d9 |
239 | DBIx::Class::Optional::Dependencies->req_list_for($msaccess_mssql_icdt), |
d1f653cf |
240 | { |
241 | 'DBD::ODBC' => 0, |
2baba3d9 |
242 | 'DateTime' => '0.55', |
243 | 'DateTime::Format::Strptime' => '1.2', |
d1f653cf |
244 | }, |
245 | 'Correct req_list_for on multi-level converging include', |
246 | ); |
247 | |
248 | is_deeply( |
2baba3d9 |
249 | DBIx::Class::Optional::Dependencies->modreq_list_for($msaccess_mssql_icdt), |
d1f653cf |
250 | { |
251 | 'DBD::ODBC' => 0, |
252 | 'Data::GUID' => 0, |
2baba3d9 |
253 | 'DateTime' => '0.55', |
254 | 'DateTime::Format::Strptime' => '1.2', |
d1f653cf |
255 | }, |
256 | 'Correct modreq_list_for on multi-level converging include', |
257 | ); |
258 | |
31c31b8d |
259 | } |
05c0614b |
260 | |
be68095d |
261 | # test multiple times to find autovivification bugs |
e3a7746c |
262 | for my $meth (qw(req_list_for modreq_list_for)) { |
be68095d |
263 | throws_ok { |
e3a7746c |
264 | DBIx::Class::Optional::Dependencies->$meth(); |
be68095d |
265 | } qr/\Qreq_list_for() expects a requirement group name/, |
e3a7746c |
266 | "$meth without groupname throws exception"; |
be68095d |
267 | |
268 | throws_ok { |
e3a7746c |
269 | DBIx::Class::Optional::Dependencies->$meth(''); |
270 | } qr/\Q$meth() expects a requirement group name/, |
271 | "$meth with empty groupname throws exception"; |
be68095d |
272 | |
273 | throws_ok { |
e3a7746c |
274 | DBIx::Class::Optional::Dependencies->$meth('invalid_groupname'); |
31c31b8d |
275 | } qr/Requirement group 'invalid_groupname' is not defined/, |
e3a7746c |
276 | "$meth with invalid groupname throws exception"; |
be68095d |
277 | } |
278 | |
05c0614b |
279 | done_testing; |