Commit | Line | Data |
05c0614b |
1 | use strict; |
2 | use warnings; |
3 | no warnings qw/once/; |
4 | |
5 | use Test::More; |
6 | use lib qw(t/lib); |
7 | use Scalar::Util; # load before we break require() |
8 | |
9 | use_ok 'DBIx::Class::Optional::Dependencies'; |
10 | |
11 | my $sqlt_dep = DBIx::Class::Optional::Dependencies->req_list_for ('deploy'); |
12 | is_deeply ( |
13 | [ keys %$sqlt_dep ], |
14 | [ 'SQL::Translator' ], |
15 | 'Correct deploy() dependency list', |
16 | ); |
17 | |
18 | # make module loading impossible, regardless of actual libpath contents |
19 | @INC = (sub { die('Optional Dep Test') } ); |
20 | |
21 | ok ( |
22 | ! DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'), |
23 | 'deploy() deps missing', |
24 | ); |
25 | |
26 | like ( |
27 | DBIx::Class::Optional::Dependencies->req_missing_for ('deploy'), |
28 | qr/^SQL::Translator \>\= \d/, |
29 | 'expected missing string contents', |
30 | ); |
31 | |
32 | like ( |
33 | DBIx::Class::Optional::Dependencies->req_errorlist_for ('deploy')->{'SQL::Translator'}, |
34 | qr/Optional Dep Test/, |
35 | 'custom exception found in errorlist', |
36 | ); |
37 | |
38 | |
39 | #make it so module appears loaded |
40 | $INC{'SQL/Translator.pm'} = 1; |
41 | $SQL::Translator::VERSION = 999; |
42 | |
43 | ok ( |
44 | ! DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'), |
45 | 'deploy() deps missing cached properly', |
46 | ); |
47 | |
48 | #reset cache |
49 | %DBIx::Class::Optional::Dependencies::req_availability_cache = (); |
50 | |
51 | |
52 | ok ( |
53 | DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'), |
54 | 'deploy() deps present', |
55 | ); |
56 | |
57 | is ( |
58 | DBIx::Class::Optional::Dependencies->req_missing_for ('deploy'), |
59 | '', |
60 | 'expected null missing string', |
61 | ); |
62 | |
63 | is_deeply ( |
64 | DBIx::Class::Optional::Dependencies->req_errorlist_for ('deploy'), |
65 | {}, |
66 | 'expected empty errorlist', |
67 | ); |
68 | |
69 | |
70 | done_testing; |