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 unsafe with $ENV{PERL5OPT}', 1
26 skip 'Lean load pattern testing unsafe with sitecustomize.pl', 1
27 if grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC;
29 skip 'Lean load pattern testing useless with $ENV{RELEASE_TESTING}', 1
30 if $ENV{RELEASE_TESTING};
32 skip 'Lean load pattern testing useless under cperl', 1
38 'Nothing was loaded before inc-test'
42 [ 'DBIx/Class/Optional/Dependencies.pm' ],
43 'Nothing was loaded other than DBIx::Class::OptDeps'
47 # check the project-local groups for sanity
49 DBIx::Class::Optional::Dependencies->req_group_list
50 } "The entire optdep list is well formed";
53 [ keys %{ DBIx::Class::Optional::Dependencies->req_list_for ('deploy') } ],
54 [ 'SQL::Translator' ],
55 'Correct deploy() dependency list',
58 # scope to break require()
61 # make module loading impossible, regardless of actual libpath contents
64 # basic test using the deploy target
65 for ('deploy', ['deploy']) {
67 # explicitly blow up cache
68 %DBIx::Class::Optional::Dependencies::req_unavailability_cache = ();
71 ! DBIx::Class::Optional::Dependencies->req_ok_for ($_),
72 'deploy() deps missing',
76 DBIx::Class::Optional::Dependencies->modreq_missing_for ($_),
79 SQL::Translator \~ [\d\.]+
82 'expected modreq missing string contents',
86 DBIx::Class::Optional::Dependencies->req_missing_for ($_),
89 SQL::Translator \~ [\d\.]+
90 \Q (see DBIx::Class::Optional::Dependencies documentation for details)\E
93 'expected missing string contents',
97 DBIx::Class::Optional::Dependencies->modreq_errorlist_for ($_)->{'SQL::Translator'},
98 qr|\QCan't locate SQL/Translator.pm|,
99 'correct "unable to locate" exception found in errorlist',
102 #make it so module appears loaded
103 local $INC{'SQL/Translator.pm'} = 1;
104 local $SQL::Translator::VERSION = 999;
107 ! DBIx::Class::Optional::Dependencies->req_ok_for ($_),
108 'deploy() deps missing cached properly from previous run',
112 %DBIx::Class::Optional::Dependencies::req_unavailability_cache = ();
115 DBIx::Class::Optional::Dependencies->req_ok_for ($_),
116 'deploy() deps present',
120 DBIx::Class::Optional::Dependencies->req_missing_for ($_),
122 'expected null missing string',
126 # use the deprecated method name
127 DBIx::Class::Optional::Dependencies->req_errorlist_for ($_),
129 'expected empty errorlist',
133 # test single-db text
134 local $ENV{DBICTEST_MYSQL_DSN};
136 DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_mysql'),
138 'unknown optional dependencies list for testing MySQL without ENV var',
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',
146 local $ENV{DBICTEST_MYSQL_DSN};
147 local $ENV{DBICTEST_PG_DSN};
151 DBIx::Class::Optional::Dependencies->modreq_list_for([shuffle qw( test_rdbms_pg binary_data )]),
152 { 'DBD::Pg' => '2.009002' },
153 'optional dependencies list for testing Postgres without envvar',
157 DBIx::Class::Optional::Dependencies->req_list_for([shuffle qw( test_rdbms_pg binary_data )]),
159 'optional dependencies list for testing Postgres without envvar',
163 DBIx::Class::Optional::Dependencies->req_list_for('rdbms_pg'),
164 { 'DBD::Pg' => '0', },
165 'optional dependencies list for using Postgres matches',
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',
174 # test combination of different requirements on same module (pg's are relatively stable)
176 DBIx::Class::Optional::Dependencies->req_list_for([shuffle qw( rdbms_pg test_rdbms_pg )]),
177 { 'DBD::Pg' => '0' },
178 'optional module dependencies list for testing Postgres matches without envvar',
182 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data )]),
183 'DBD::Pg~2.009002 as well as the following group(s) of environment variables: DBICTEST_PG_DSN/..._USER/..._PASS',
184 'optional dependencies for testing Postgres without envvar'
188 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( test_rdbms_mysql test_rdbms_pg binary_data)]),
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',
190 'optional dependencies for testing Postgres+MySQL without envvars'
193 $ENV{DBICTEST_PG_DSN} = 'boo';
195 DBIx::Class::Optional::Dependencies->modreq_list_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data)]),
196 { 'DBD::Pg' => '2.009002' },
197 'optional module dependencies list for testing Postgres matches with envvar',
201 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( rdbms_pg test_rdbms_pg binary_data )]),
203 'optional dependencies error text for testing Postgres matches with evvar',
207 my %expected_icdt_base = ( DateTime => '0.55', 'DateTime::TimeZone::OlsonDB' => 0 );
209 my $mysql_icdt = [shuffle qw( test_rdbms_mysql ic_dt )];
212 DBIx::Class::Optional::Dependencies->modreq_list_for($mysql_icdt),
216 'DateTime::Format::MySQL' => 0,
218 'optional module dependencies list for testing ICDT MySQL without envvar',
222 DBIx::Class::Optional::Dependencies->req_list_for($mysql_icdt),
223 \%expected_icdt_base,
224 'optional dependencies list for testing ICDT MySQL without envvar',
228 DBIx::Class::Optional::Dependencies->req_missing_for($mysql_icdt),
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",
230 'missing optional dependencies for testing ICDT MySQL without envvars'
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';
236 my $msaccess_mssql_icdt = [ shuffle qw( test_rdbms_msaccess_odbc test_rdbms_mssql_odbc ic_dt ) ];
238 DBIx::Class::Optional::Dependencies->req_missing_for($msaccess_mssql_icdt),
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',
240 'Correct req_missing_for on multi-level converging include',
244 DBIx::Class::Optional::Dependencies->modreq_missing_for($msaccess_mssql_icdt),
245 'Data::GUID DateTime~0.55 DateTime::Format::Strptime~1.2 DateTime::TimeZone::OlsonDB DBD::ODBC',
246 'Correct modreq_missing_for on multi-level converging include',
250 DBIx::Class::Optional::Dependencies->req_list_for($msaccess_mssql_icdt),
253 'DateTime::Format::Strptime' => '1.2',
256 'Correct req_list_for on multi-level converging include',
260 DBIx::Class::Optional::Dependencies->modreq_list_for($msaccess_mssql_icdt),
264 'DateTime::Format::Strptime' => '1.2',
267 'Correct modreq_list_for on multi-level converging include',
272 # test multiple times to find autovivification bugs
273 for my $meth (qw(req_list_for modreq_list_for)) {
275 DBIx::Class::Optional::Dependencies->$meth();
276 } qr/\Qreq_list_for() expects a requirement group name/,
277 "$meth without groupname throws exception";
280 DBIx::Class::Optional::Dependencies->$meth('');
281 } qr/\Q$meth() expects a requirement group name/,
282 "$meth with empty groupname throws exception";
285 DBIx::Class::Optional::Dependencies->$meth('invalid_groupname');
286 } qr/Requirement group 'invalid_groupname' is not defined/,
287 "$meth with invalid groupname throws exception";