1 my ($inc_before, $inc_after);
3 $inc_before = [ keys %INC ];
4 require DBIx::Class::Optional::Dependencies;
5 $inc_after = [ keys %INC ];
15 # load before we break require()
19 use List::Util 'shuffle';
23 skip 'Lean load pattern testing makes no sense with TempExtlib', 1
24 if grep { $_ =~ /TempExtlib/ } @INC;
26 skip 'Lean load pattern testing unsafe with $ENV{PERL5OPT}', 1
29 skip 'Lean load pattern testing unsafe with sitecustomize.pl', 1
30 if grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC;
32 skip 'Lean load pattern testing useless with $ENV{RELEASE_TESTING}', 1
33 if $ENV{RELEASE_TESTING};
35 skip 'Lean load pattern testing useless under cperl', 1
41 'Nothing was loaded before inc-test'
45 [ 'DBIx/Class/Optional/Dependencies.pm' ],
46 'Nothing was loaded other than DBIx::Class::OptDeps'
50 # check the project-local groups for sanity
52 DBIx::Class::Optional::Dependencies->req_group_list
53 } "The entire optdep list is well formed";
56 [ keys %{ DBIx::Class::Optional::Dependencies->req_list_for ('deploy') } ],
57 [ 'SQL::Translator' ],
58 'Correct deploy() dependency list',
61 # scope to break require()
64 # make module loading impossible, regardless of actual libpath contents
67 # basic test using the deploy target
68 for ('deploy', ['deploy']) {
70 # explicitly blow up cache
71 %DBIx::Class::Optional::Dependencies::req_unavailability_cache = ();
74 ! DBIx::Class::Optional::Dependencies->req_ok_for ($_),
75 'deploy() deps missing',
79 DBIx::Class::Optional::Dependencies->modreq_missing_for ($_),
82 SQL::Translator \~ [\d\.]+
85 'expected modreq missing string contents',
89 DBIx::Class::Optional::Dependencies->req_missing_for ($_),
92 SQL::Translator \~ [\d\.]+
93 \Q (see DBIx::Class::Optional::Dependencies documentation for details)\E
96 'expected missing string contents',
100 DBIx::Class::Optional::Dependencies->modreq_errorlist_for ($_)->{'SQL::Translator'},
101 qr|\QCan't locate SQL/Translator.pm|,
102 'correct "unable to locate" exception found in errorlist',
105 #make it so module appears loaded
106 local $INC{'SQL/Translator.pm'} = 1;
107 local $SQL::Translator::VERSION = 999;
110 ! DBIx::Class::Optional::Dependencies->req_ok_for ($_),
111 'deploy() deps missing cached properly from previous run',
115 %DBIx::Class::Optional::Dependencies::req_unavailability_cache = ();
118 DBIx::Class::Optional::Dependencies->req_ok_for ($_),
119 'deploy() deps present',
123 DBIx::Class::Optional::Dependencies->req_missing_for ($_),
125 'expected null missing string',
129 # use the deprecated method name
130 DBIx::Class::Optional::Dependencies->req_errorlist_for ($_),
132 'expected empty errorlist',
136 # test single-db text
137 local $ENV{DBICTEST_MYSQL_DSN};
139 DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_mysql'),
141 'unknown optional dependencies list for testing MySQL without ENV var',
144 DBIx::Class::Optional::Dependencies->modreq_list_for('test_rdbms_mysql'),
145 { 'DBD::mysql' => 0 },
146 'correct optional module dependencies list for testing MySQL without ENV var',
149 local $ENV{DBICTEST_MYSQL_DSN};
150 local $ENV{DBICTEST_PG_DSN};
154 DBIx::Class::Optional::Dependencies->modreq_list_for([shuffle qw( test_rdbms_pg binary_data )]),
155 { 'DBD::Pg' => '2.009002' },
156 'optional dependencies list for testing Postgres without envvar',
160 DBIx::Class::Optional::Dependencies->req_list_for([shuffle qw( test_rdbms_pg binary_data )]),
162 'optional dependencies list for testing Postgres without envvar',
166 DBIx::Class::Optional::Dependencies->req_list_for('rdbms_pg'),
167 { 'DBD::Pg' => '0', },
168 'optional dependencies list for using Postgres matches',
172 DBIx::Class::Optional::Dependencies->req_missing_for('rdbms_pg'),
173 'DBD::Pg (see DBIx::Class::Optional::Dependencies documentation for details)',
174 'optional dependencies missing list for using Postgres matches',
177 # test combination of different requirements on same module (pg's are relatively stable)
179 DBIx::Class::Optional::Dependencies->req_list_for([shuffle qw( rdbms_pg test_rdbms_pg )]),
180 { 'DBD::Pg' => '0' },
181 'optional module dependencies list for testing Postgres matches without envvar',
185 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data )]),
186 'DBD::Pg~2.009002 as well as the following group(s) of environment variables: DBICTEST_PG_DSN/..._USER/..._PASS',
187 'optional dependencies for testing Postgres without envvar'
191 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( test_rdbms_mysql test_rdbms_pg binary_data)]),
192 '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',
193 'optional dependencies for testing Postgres+MySQL without envvars'
196 $ENV{DBICTEST_PG_DSN} = 'boo';
198 DBIx::Class::Optional::Dependencies->modreq_list_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data)]),
199 { 'DBD::Pg' => '2.009002' },
200 'optional module dependencies list for testing Postgres matches with envvar',
204 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data )]),
206 'optional dependencies error text for testing Postgres matches with evvar',
210 my %expected_icdt_base = ( DateTime => '0.55', 'DateTime::TimeZone::OlsonDB' => 0 );
212 my $mysql_icdt = [shuffle qw( test_rdbms_mysql ic_dt )];
215 DBIx::Class::Optional::Dependencies->modreq_list_for($mysql_icdt),
219 'DateTime::Format::MySQL' => 0,
221 'optional module dependencies list for testing ICDT MySQL without envvar',
225 DBIx::Class::Optional::Dependencies->req_list_for($mysql_icdt),
226 \%expected_icdt_base,
227 'optional dependencies list for testing ICDT MySQL without envvar',
231 DBIx::Class::Optional::Dependencies->req_missing_for($mysql_icdt),
232 "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",
233 'missing optional dependencies for testing ICDT MySQL without envvars'
236 # test multi-level include with a variable and mandatory part converging on same included dep
237 local $ENV{DBICTEST_MSACCESS_ODBC_DSN};
238 local $ENV{DBICTEST_MSSQL_ODBC_DSN} = 'foo';
239 my $msaccess_mssql_icdt = [ shuffle qw( test_rdbms_msaccess_odbc test_rdbms_mssql_odbc ic_dt ) ];
241 DBIx::Class::Optional::Dependencies->req_missing_for($msaccess_mssql_icdt),
242 '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',
243 'Correct req_missing_for on multi-level converging include',
247 DBIx::Class::Optional::Dependencies->modreq_missing_for($msaccess_mssql_icdt),
248 'Data::GUID DateTime~0.55 DateTime::Format::Strptime~1.2 DateTime::TimeZone::OlsonDB DBD::ODBC',
249 'Correct modreq_missing_for on multi-level converging include',
253 DBIx::Class::Optional::Dependencies->req_list_for($msaccess_mssql_icdt),
256 'DateTime::Format::Strptime' => '1.2',
259 'Correct req_list_for on multi-level converging include',
263 DBIx::Class::Optional::Dependencies->modreq_list_for($msaccess_mssql_icdt),
267 'DateTime::Format::Strptime' => '1.2',
270 'Correct modreq_list_for on multi-level converging include',
275 # test multiple times to find autovivification bugs
276 for my $meth (qw(req_list_for modreq_list_for)) {
278 DBIx::Class::Optional::Dependencies->$meth();
279 } qr/\Qreq_list_for() expects a requirement group name/,
280 "$meth without groupname throws exception";
283 DBIx::Class::Optional::Dependencies->$meth('');
284 } qr/\Q$meth() expects a requirement group name/,
285 "$meth with empty groupname throws exception";
288 DBIx::Class::Optional::Dependencies->$meth('invalid_groupname');
289 } qr/Requirement group 'invalid_groupname' is not defined/,
290 "$meth with invalid groupname throws exception";