X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=xt%2Foptional_deps.t;h=66f6a6568fc06e82d6ccae9938013f457af4ab7f;hb=be68095d16b02db81aa1c37dfd6f6595f19d1ac2;hp=5e35930a2765b9b9aa9e7243c08744b9651df436;hpb=3c3e76bd18fc509533a30b09cd64b46cef35d6c5;p=dbsrgits%2FDBIx-Class.git diff --git a/xt/optional_deps.t b/xt/optional_deps.t index 5e35930..66f6a65 100644 --- a/xt/optional_deps.t +++ b/xt/optional_deps.t @@ -3,9 +3,10 @@ use warnings; no warnings qw/once/; use Test::More; +use Test::Exception; use lib qw(t/lib); use Scalar::Util; # load before we break require() -use Carp (); # Carp is not used in the test, but we want to have it loaded for proper %INC comparison +use Carp (); # Carp is not used in the test, but we want to have it loaded for proper %INC comparison # a dummy test which lazy-loads more modules (so we can compare INC below) ok (1); @@ -15,6 +16,13 @@ ok (1); my $inc_before = [ keys %INC ]; ok ( (! grep { $_ =~ m|DBIx/Class| } @$inc_before ), 'Nothing DBIC related is yet loaded'); +# DBIx::Class::Optional::Dependencies queries $ENV at compile time +# to build the optional requirements +BEGIN { + $ENV{DBICTEST_PG_DSN} = '1'; + $ENV{DBICTEST_ORA_DSN} = undef; +} + use_ok 'DBIx::Class::Optional::Dependencies'; my $inc_after = [ keys %INC ]; @@ -33,25 +41,26 @@ is_deeply ( ); # make module loading impossible, regardless of actual libpath contents -@INC = (sub { die('Optional Dep Test') } ); - -ok ( - ! DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'), - 'deploy() deps missing', -); - -like ( - DBIx::Class::Optional::Dependencies->req_missing_for ('deploy'), - qr/^SQL::Translator \>\= \d/, - 'expected missing string contents', -); - -like ( - DBIx::Class::Optional::Dependencies->req_errorlist_for ('deploy')->{'SQL::Translator'}, - qr/Optional Dep Test/, - 'custom exception found in errorlist', -); - +{ + local @INC = (sub { die('Optional Dep Test') } ); + + ok ( + ! DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'), + 'deploy() deps missing', + ); + + like ( + DBIx::Class::Optional::Dependencies->req_missing_for ('deploy'), + qr/^SQL::Translator \>\= \d/, + 'expected missing string contents', + ); + + like ( + DBIx::Class::Optional::Dependencies->req_errorlist_for ('deploy')->{'SQL::Translator'}, + qr/Optional Dep Test/, + 'custom exception found in errorlist', + ); +} #make it so module appears loaded $INC{'SQL/Translator.pm'} = 1; @@ -83,5 +92,39 @@ is_deeply ( 'expected empty errorlist', ); +# test multiple times to find autovivification bugs +for (1..2) { + throws_ok { + DBIx::Class::Optional::Dependencies->req_list_for(); + } qr/\Qreq_list_for() expects a requirement group name/, + "req_list_for without groupname throws exception on run $_"; + + throws_ok { + DBIx::Class::Optional::Dependencies->req_list_for(''); + } qr/\Qreq_list_for() expects a requirement group name/, + "req_list_for with empty groupname throws exception on run $_"; + + throws_ok { + DBIx::Class::Optional::Dependencies->req_list_for('invalid_groupname'); + } qr/Requirement group 'invalid_groupname' does not exist/, + "req_list_for with invalid groupname throws exception on run $_"; +} + +is_deeply( + DBIx::Class::Optional::Dependencies->req_list_for('rdbms_pg'), + { + 'DBD::Pg' => '0', + }, 'optional dependencies for deploying to Postgres ok'); + +is_deeply( + DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_pg'), + { + 'Sys::SigAction' => '0', + 'DBD::Pg' => '2.009002', + }, 'optional dependencies for testing Postgres with ENV var ok'); + +is_deeply( + DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_oracle'), + {}, 'optional dependencies for testing Oracle without ENV var ok'); done_testing;