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';
22 skip 'Lean load pattern testing unsafe with $ENV{PERL5OPT}', 1 if $ENV{PERL5OPT};
23 skip 'Lean load pattern testing useless with $ENV{RELEASE_TESTING}', 1 if $ENV{RELEASE_TESTING};
27 'Nothing was loaded before inc-test'
31 [ 'DBIx/Class/Optional/Dependencies.pm' ],
32 'Nothing was loaded other than DBIx::Class::OptDeps'
36 # check the project-local groups for sanity
38 DBIx::Class::Optional::Dependencies->req_group_list
39 } "The entire optdep list is well formed";
42 [ keys %{ DBIx::Class::Optional::Dependencies->req_list_for ('deploy') } ],
43 [ 'SQL::Translator' ],
44 'Correct deploy() dependency list',
47 # scope to break require()
50 # make module loading impossible, regardless of actual libpath contents
53 # basic test using the deploy target
54 for ('deploy', ['deploy']) {
56 # explicitly blow up cache
57 %DBIx::Class::Optional::Dependencies::req_unavailability_cache = ();
60 ! DBIx::Class::Optional::Dependencies->req_ok_for ($_),
61 'deploy() deps missing',
65 DBIx::Class::Optional::Dependencies->modreq_missing_for ($_),
68 SQL::Translator \~ [\d\.]+
71 'expected modreq missing string contents',
75 DBIx::Class::Optional::Dependencies->req_missing_for ($_),
78 SQL::Translator \~ [\d\.]+
79 \Q (see DBIx::Class::Optional::Dependencies documentation for details)\E
82 'expected missing string contents',
86 DBIx::Class::Optional::Dependencies->modreq_errorlist_for ($_)->{'SQL::Translator'},
87 qr|\QCan't locate SQL/Translator.pm|,
88 'correct "unable to locate" exception found in errorlist',
91 #make it so module appears loaded
92 local $INC{'SQL/Translator.pm'} = 1;
93 local $SQL::Translator::VERSION = 999;
96 ! DBIx::Class::Optional::Dependencies->req_ok_for ($_),
97 'deploy() deps missing cached properly from previous run',
101 %DBIx::Class::Optional::Dependencies::req_unavailability_cache = ();
104 DBIx::Class::Optional::Dependencies->req_ok_for ($_),
105 'deploy() deps present',
109 DBIx::Class::Optional::Dependencies->req_missing_for ($_),
111 'expected null missing string',
115 # use the deprecated method name
116 DBIx::Class::Optional::Dependencies->req_errorlist_for ($_),
118 'expected empty errorlist',
122 # test single-db text
123 local $ENV{DBICTEST_MYSQL_DSN};
125 DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_mysql'),
127 'unknown optional dependencies list for testing MySQL without ENV var',
130 DBIx::Class::Optional::Dependencies->modreq_list_for('test_rdbms_mysql'),
131 { 'DBD::mysql' => 0 },
132 'correct optional module dependencies list for testing MySQL without ENV var',
135 local $ENV{DBICTEST_MYSQL_DSN};
136 local $ENV{DBICTEST_PG_DSN};
140 DBIx::Class::Optional::Dependencies->modreq_list_for('test_rdbms_pg'),
141 { 'DBD::Pg' => '2.009002' },
142 'optional dependencies list for testing Postgres without envvar',
146 DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_pg'),
148 'optional dependencies list for testing Postgres without envvar',
152 DBIx::Class::Optional::Dependencies->req_list_for('rdbms_pg'),
153 { 'DBD::Pg' => '0', },
154 'optional dependencies list for using Postgres matches',
158 DBIx::Class::Optional::Dependencies->req_missing_for('rdbms_pg'),
159 'DBD::Pg (see DBIx::Class::Optional::Dependencies documentation for details)',
160 'optional dependencies missing list for using Postgres matches',
163 # test combination of different requirements on same module (pg's are relatively stable)
165 DBIx::Class::Optional::Dependencies->req_list_for([shuffle qw( rdbms_pg test_rdbms_pg )]),
166 { 'DBD::Pg' => '0' },
167 'optional module dependencies list for testing Postgres matches without envvar',
171 DBIx::Class::Optional::Dependencies->req_missing_for([qw( rdbms_pg test_rdbms_pg )]),
172 'DBD::Pg~2.009002 as well as the following group(s) of environment variables: DBICTEST_PG_DSN/..._USER/..._PASS',
173 'optional dependencies for testing Postgres without envvar'
177 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( test_rdbms_mysql test_rdbms_pg )]),
178 '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',
179 'optional dependencies for testing Postgres+MySQL without envvars'
182 $ENV{DBICTEST_PG_DSN} = 'boo';
184 DBIx::Class::Optional::Dependencies->modreq_list_for([shuffle qw( rdbms_pg test_rdbms_pg )]),
185 { 'DBD::Pg' => '2.009002' },
186 'optional module dependencies list for testing Postgres matches with envvar',
190 DBIx::Class::Optional::Dependencies->req_missing_for([shuffle qw( rdbms_pg test_rdbms_pg )]),
192 'optional dependencies error text for testing Postgres matches with evvar',
196 my $mysql_icdt = [shuffle qw( test_rdbms_mysql icdt )];
199 DBIx::Class::Optional::Dependencies->modreq_list_for($mysql_icdt),
201 'DateTime' => '0.55',
203 'DateTime::Format::MySQL' => 0,
205 'optional module dependencies list for testing ICDT MySQL without envvar',
209 DBIx::Class::Optional::Dependencies->req_list_for($mysql_icdt),
211 'DateTime' => '0.55',
213 'optional dependencies list for testing ICDT MySQL without envvar',
217 DBIx::Class::Optional::Dependencies->req_missing_for($mysql_icdt),
218 'DateTime~0.55 DateTime::Format::MySQL DBD::mysql as well as the following group(s) of environment variables: DBICTEST_MYSQL_DSN/..._USER/..._PASS',
219 'missing optional dependencies for testing ICDT MySQL without envvars'
222 # test multi-level include with a variable and mandatory part converging on same included dep
223 local $ENV{DBICTEST_MSACCESS_ODBC_DSN};
224 local $ENV{DBICTEST_MSSQL_ODBC_DSN} = 'foo';
225 my $msaccess_mssql_icdt = [ shuffle qw( test_rdbms_msaccess_odbc test_rdbms_mssql_odbc icdt ) ];
227 DBIx::Class::Optional::Dependencies->req_missing_for($msaccess_mssql_icdt),
228 'Data::GUID DateTime~0.55 DateTime::Format::Strptime~1.2 DBD::ODBC as well as the following group(s) of environment variables: DBICTEST_MSACCESS_ODBC_DSN/..._USER/..._PASS',
229 'Correct req_missing_for on multi-level converging include',
233 DBIx::Class::Optional::Dependencies->modreq_missing_for($msaccess_mssql_icdt),
234 'Data::GUID DateTime~0.55 DateTime::Format::Strptime~1.2 DBD::ODBC',
235 'Correct modreq_missing_for on multi-level converging include',
239 DBIx::Class::Optional::Dependencies->req_list_for($msaccess_mssql_icdt),
242 'DateTime' => '0.55',
243 'DateTime::Format::Strptime' => '1.2',
245 'Correct req_list_for on multi-level converging include',
249 DBIx::Class::Optional::Dependencies->modreq_list_for($msaccess_mssql_icdt),
253 'DateTime' => '0.55',
254 'DateTime::Format::Strptime' => '1.2',
256 'Correct modreq_list_for on multi-level converging include',
261 # test multiple times to find autovivification bugs
262 for my $meth (qw(req_list_for modreq_list_for)) {
264 DBIx::Class::Optional::Dependencies->$meth();
265 } qr/\Qreq_list_for() expects a requirement group name/,
266 "$meth without groupname throws exception";
269 DBIx::Class::Optional::Dependencies->$meth('');
270 } qr/\Q$meth() expects a requirement group name/,
271 "$meth with empty groupname throws exception";
274 DBIx::Class::Optional::Dependencies->$meth('invalid_groupname');
275 } qr/Requirement group 'invalid_groupname' is not defined/,
276 "$meth with invalid groupname throws exception";