1 my ($inc_before, $inc_after);
3 $inc_before = [ keys %INC ];
4 require DBIx::Class::Optional::Dependencies;
5 $inc_after = [ keys %INC ];
16 plan skip_all => 'This test breaking module loading interferes with PERL_UNICODE on perls prior to 5.12'
17 if exists $ENV{PERL_UNICODE} and "$]" < 5.012;
20 # load before we break require()
24 use List::Util 'shuffle';
28 skip 'Lean load pattern testing makes no sense with TempExtlib', 1
29 if grep { $_ =~ /TempExtlib/ } @INC;
31 skip 'Lean load pattern testing unsafe with $ENV{PERL5OPT}', 1
34 skip 'Lean load pattern testing unsafe with sitecustomize.pl', 1
35 if grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC;
37 skip 'Lean load pattern testing useless with $ENV{RELEASE_TESTING}', 1
38 if $ENV{RELEASE_TESTING};
40 skip 'Lean load pattern testing useless under cperl', 1
46 'Nothing was loaded before inc-test'
50 [ 'DBIx/Class/Optional/Dependencies.pm' ],
51 'Nothing was loaded other than DBIx::Class::OptDeps'
55 # check the project-local groups for sanity
57 DBIx::Class::Optional::Dependencies->req_group_list
58 } "The entire optdep list is well formed";
61 [ keys %{ DBIx::Class::Optional::Dependencies->req_list_for ('deploy') } ],
62 [ 'SQL::Translator' ],
63 'Correct deploy() dependency list',
66 # scope to break require()
69 # make module loading impossible, regardless of actual libpath contents
72 # basic test using the deploy target
73 for ('deploy', ['deploy']) {
75 # explicitly blow up cache
76 %DBIx::Class::Optional::Dependencies::req_unavailability_cache = ();
79 ! DBIx::Class::Optional::Dependencies->req_ok_for ($_),
80 'deploy() deps missing',
84 DBIx::Class::Optional::Dependencies->modreq_missing_for ($_),
87 SQL::Translator \~ [\d\.]+
90 'expected modreq missing string contents',
94 DBIx::Class::Optional::Dependencies->req_missing_for ($_),
97 SQL::Translator \~ [\d\.]+
98 \Q (see DBIx::Class::Optional::Dependencies documentation for details)\E
101 'expected missing string contents',
105 DBIx::Class::Optional::Dependencies->modreq_errorlist_for ($_)->{'SQL::Translator'},
106 qr|\QCan't locate SQL/Translator.pm|,
107 'correct "unable to locate" exception found in errorlist',
110 #make it so module appears loaded
111 local $INC{'SQL/Translator.pm'} = 1;
112 local $SQL::Translator::VERSION = 999;
115 ! DBIx::Class::Optional::Dependencies->req_ok_for ($_),
116 'deploy() deps missing cached properly from previous run',
120 %DBIx::Class::Optional::Dependencies::req_unavailability_cache = ();
123 DBIx::Class::Optional::Dependencies->req_ok_for ($_),
124 'deploy() deps present',
128 DBIx::Class::Optional::Dependencies->req_missing_for ($_),
130 'expected null missing string',
134 # use the deprecated method name
135 DBIx::Class::Optional::Dependencies->req_errorlist_for ($_),
137 'expected empty errorlist',
141 # test single-db text
142 local $ENV{DBICTEST_MYSQL_DSN};
144 DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_mysql'),
146 'unknown optional dependencies list for testing MySQL without ENV var',
149 DBIx::Class::Optional::Dependencies->modreq_list_for('test_rdbms_mysql'),
150 { 'DBD::mysql' => 0 },
151 'correct optional module dependencies list for testing MySQL without ENV var',
154 local $ENV{DBICTEST_MYSQL_DSN};
155 local $ENV{DBICTEST_PG_DSN};
159 DBIx::Class::Optional::Dependencies->modreq_list_for([shuffle qw( test_rdbms_pg binary_data )]),
160 { 'DBD::Pg' => '2.009002' },
161 'optional dependencies list for testing Postgres without envvar',
165 DBIx::Class::Optional::Dependencies->req_list_for([shuffle qw( test_rdbms_pg binary_data )]),
167 'optional dependencies list for testing Postgres without envvar',
171 DBIx::Class::Optional::Dependencies->req_list_for('rdbms_pg'),
172 { 'DBD::Pg' => '0', },
173 'optional dependencies list for using Postgres matches',
177 DBIx::Class::Optional::Dependencies->req_missing_for('rdbms_pg'),
178 'DBD::Pg (see DBIx::Class::Optional::Dependencies documentation for details)',
179 'optional dependencies missing list for using Postgres matches',
182 # test combination of different requirements on same module (pg's are relatively stable)
184 DBIx::Class::Optional::Dependencies->req_list_for([shuffle qw( rdbms_pg test_rdbms_pg )]),
185 { 'DBD::Pg' => '0' },
186 'optional module dependencies list for testing Postgres matches without envvar',
190 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data )]),
191 'DBD::Pg~2.009002 as well as the following group(s) of environment variables: DBICTEST_PG_DSN/..._USER/..._PASS',
192 'optional dependencies for testing Postgres without envvar'
196 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( test_rdbms_mysql test_rdbms_pg binary_data)]),
197 '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',
198 'optional dependencies for testing Postgres+MySQL without envvars'
201 $ENV{DBICTEST_PG_DSN} = 'boo';
203 DBIx::Class::Optional::Dependencies->modreq_list_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data)]),
204 { 'DBD::Pg' => '2.009002' },
205 'optional module dependencies list for testing Postgres matches with envvar',
209 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data )]),
211 'optional dependencies error text for testing Postgres matches with evvar',
215 my %expected_icdt_base = ( DateTime => '0.55', 'DateTime::TimeZone::OlsonDB' => 0 );
217 my $mysql_icdt = [shuffle qw( test_rdbms_mysql ic_dt )];
220 DBIx::Class::Optional::Dependencies->modreq_list_for($mysql_icdt),
224 'DateTime::Format::MySQL' => 0,
226 'optional module dependencies list for testing ICDT MySQL without envvar',
230 DBIx::Class::Optional::Dependencies->req_list_for($mysql_icdt),
231 \%expected_icdt_base,
232 'optional dependencies list for testing ICDT MySQL without envvar',
236 DBIx::Class::Optional::Dependencies->req_missing_for($mysql_icdt),
237 "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",
238 'missing optional dependencies for testing ICDT MySQL without envvars'
241 # test multi-level include with a variable and mandatory part converging on same included dep
242 local $ENV{DBICTEST_MSACCESS_ODBC_DSN};
243 local $ENV{DBICTEST_MSSQL_ODBC_DSN} = 'foo';
244 my $msaccess_mssql_icdt = [ shuffle qw( test_rdbms_msaccess_odbc test_rdbms_mssql_odbc ic_dt ) ];
246 DBIx::Class::Optional::Dependencies->req_missing_for($msaccess_mssql_icdt),
247 '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',
248 'Correct req_missing_for on multi-level converging include',
252 DBIx::Class::Optional::Dependencies->modreq_missing_for($msaccess_mssql_icdt),
253 'Data::GUID DateTime~0.55 DateTime::Format::Strptime~1.2 DateTime::TimeZone::OlsonDB DBD::ODBC',
254 'Correct modreq_missing_for on multi-level converging include',
258 DBIx::Class::Optional::Dependencies->req_list_for($msaccess_mssql_icdt),
261 'DateTime::Format::Strptime' => '1.2',
264 'Correct req_list_for on multi-level converging include',
268 DBIx::Class::Optional::Dependencies->modreq_list_for($msaccess_mssql_icdt),
272 'DateTime::Format::Strptime' => '1.2',
275 'Correct modreq_list_for on multi-level converging include',
280 # test multiple times to find autovivification bugs
281 for my $meth (qw(req_list_for modreq_list_for)) {
283 DBIx::Class::Optional::Dependencies->$meth();
284 } qr/\Qreq_list_for() expects a requirement group name/,
285 "$meth without groupname throws exception";
288 DBIx::Class::Optional::Dependencies->$meth('');
289 } qr/\Q$meth() expects a requirement group name/,
290 "$meth with empty groupname throws exception";
293 DBIx::Class::Optional::Dependencies->$meth('invalid_groupname');
294 } qr/Requirement group 'invalid_groupname' is not defined/,
295 "$meth with invalid groupname throws exception";