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