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