Commit | Line | Data |
05c0614b |
1 | use strict; |
2 | use warnings; |
3 | no warnings qw/once/; |
4 | |
5 | use Test::More; |
be68095d |
6 | use Test::Exception; |
05c0614b |
7 | use lib qw(t/lib); |
8 | use Scalar::Util; # load before we break require() |
d8799bab |
9 | use Carp (); # Carp is not used in the test, but we want to have it loaded for proper %INC comparison |
3c3e76bd |
10 | |
11 | # a dummy test which lazy-loads more modules (so we can compare INC below) |
12 | ok (1); |
13 | |
14 | # record contents of %INC - makes sure there are no extra deps slipping into |
15 | # Opt::Dep. |
16 | my $inc_before = [ keys %INC ]; |
17 | ok ( (! grep { $_ =~ m|DBIx/Class| } @$inc_before ), 'Nothing DBIC related is yet loaded'); |
05c0614b |
18 | |
be68095d |
19 | # DBIx::Class::Optional::Dependencies queries $ENV at compile time |
20 | # to build the optional requirements |
21 | BEGIN { |
22 | $ENV{DBICTEST_PG_DSN} = '1'; |
efee51b7 |
23 | delete $ENV{DBICTEST_ORA_DSN}; |
be68095d |
24 | } |
25 | |
05c0614b |
26 | use_ok 'DBIx::Class::Optional::Dependencies'; |
27 | |
3c3e76bd |
28 | my $inc_after = [ keys %INC ]; |
29 | |
30 | is_deeply ( |
31 | [ sort @$inc_after], |
32 | [ sort (@$inc_before, 'DBIx/Class/Optional/Dependencies.pm') ], |
33 | 'Nothing loaded other than DBIx::Class::OptDeps', |
34 | ); |
35 | |
05c0614b |
36 | my $sqlt_dep = DBIx::Class::Optional::Dependencies->req_list_for ('deploy'); |
37 | is_deeply ( |
38 | [ keys %$sqlt_dep ], |
39 | [ 'SQL::Translator' ], |
40 | 'Correct deploy() dependency list', |
41 | ); |
42 | |
43 | # make module loading impossible, regardless of actual libpath contents |
d8799bab |
44 | { |
45 | local @INC = (sub { die('Optional Dep Test') } ); |
46 | |
47 | ok ( |
48 | ! DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'), |
49 | 'deploy() deps missing', |
50 | ); |
51 | |
52 | like ( |
53 | DBIx::Class::Optional::Dependencies->req_missing_for ('deploy'), |
54 | qr/^SQL::Translator \>\= \d/, |
55 | 'expected missing string contents', |
56 | ); |
57 | |
58 | like ( |
59 | DBIx::Class::Optional::Dependencies->req_errorlist_for ('deploy')->{'SQL::Translator'}, |
60 | qr/Optional Dep Test/, |
61 | 'custom exception found in errorlist', |
62 | ); |
63 | } |
05c0614b |
64 | |
65 | #make it so module appears loaded |
66 | $INC{'SQL/Translator.pm'} = 1; |
67 | $SQL::Translator::VERSION = 999; |
68 | |
69 | ok ( |
70 | ! DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'), |
71 | 'deploy() deps missing cached properly', |
72 | ); |
73 | |
74 | #reset cache |
75 | %DBIx::Class::Optional::Dependencies::req_availability_cache = (); |
76 | |
77 | |
78 | ok ( |
79 | DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'), |
80 | 'deploy() deps present', |
81 | ); |
82 | |
83 | is ( |
84 | DBIx::Class::Optional::Dependencies->req_missing_for ('deploy'), |
85 | '', |
86 | 'expected null missing string', |
87 | ); |
88 | |
89 | is_deeply ( |
90 | DBIx::Class::Optional::Dependencies->req_errorlist_for ('deploy'), |
91 | {}, |
92 | 'expected empty errorlist', |
93 | ); |
94 | |
be68095d |
95 | # test multiple times to find autovivification bugs |
96 | for (1..2) { |
97 | throws_ok { |
98 | DBIx::Class::Optional::Dependencies->req_list_for(); |
99 | } qr/\Qreq_list_for() expects a requirement group name/, |
100 | "req_list_for without groupname throws exception on run $_"; |
101 | |
102 | throws_ok { |
103 | DBIx::Class::Optional::Dependencies->req_list_for(''); |
104 | } qr/\Qreq_list_for() expects a requirement group name/, |
105 | "req_list_for with empty groupname throws exception on run $_"; |
106 | |
107 | throws_ok { |
108 | DBIx::Class::Optional::Dependencies->req_list_for('invalid_groupname'); |
109 | } qr/Requirement group 'invalid_groupname' does not exist/, |
110 | "req_list_for with invalid groupname throws exception on run $_"; |
111 | } |
112 | |
113 | is_deeply( |
114 | DBIx::Class::Optional::Dependencies->req_list_for('rdbms_pg'), |
115 | { |
116 | 'DBD::Pg' => '0', |
117 | }, 'optional dependencies for deploying to Postgres ok'); |
118 | |
119 | is_deeply( |
120 | DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_pg'), |
121 | { |
a4fc1239 |
122 | $^O ne 'MSWin32' ? ('Sys::SigAction' => '0') : (), |
be68095d |
123 | 'DBD::Pg' => '2.009002', |
124 | }, 'optional dependencies for testing Postgres with ENV var ok'); |
125 | |
126 | is_deeply( |
127 | DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_oracle'), |
128 | {}, 'optional dependencies for testing Oracle without ENV var ok'); |
129 | |
05c0614b |
130 | done_testing; |