Commit | Line | Data |
0dc418cb |
1 | ### Module::Load::Conditional test suite ### |
3fa779ab |
2 | ### this should no longer be needed |
3 | # BEGIN { |
4 | # if( $ENV{PERL_CORE} ) { |
5 | # chdir '../lib/Module/Load/Conditional' |
6 | # if -d '../lib/Module/Load/Conditional'; |
7 | # unshift @INC, '../../../..'; |
8 | # |
9 | # ### fix perl location too |
10 | # $^X = '../../../../../t/' . $^X; |
11 | # } |
12 | # } |
13 | |
14 | BEGIN { use FindBin } |
0dc418cb |
15 | BEGIN { chdir 't' if -d 't' } |
16 | |
17 | use strict; |
0dc418cb |
18 | use File::Spec (); |
3fa779ab |
19 | use Test::More 'no_plan'; |
20 | |
21 | use constant ON_VMS => $^O eq 'VMS'; |
0dc418cb |
22 | |
3fa779ab |
23 | use lib "$FindBin::Bin/../lib"; |
24 | use lib "$FindBin::Bin/to_load"; |
0dc418cb |
25 | |
91e53322 |
26 | use_ok( 'Module::Load::Conditional' ); |
0dc418cb |
27 | |
28 | ### stupid stupid warnings ### |
29 | { $Module::Load::Conditional::VERBOSE = |
30 | $Module::Load::Conditional::VERBOSE = 0; |
31 | |
32 | *can_load = *Module::Load::Conditional::can_load |
33 | = *Module::Load::Conditional::can_load; |
34 | *check_install = *Module::Load::Conditional::check_install |
35 | = *Module::Load::Conditional::check_install; |
36 | *requires = *Module::Load::Conditional::requires |
37 | = *Module::Load::Conditional::requires; |
38 | } |
39 | |
40 | { |
41 | my $rv = check_install( |
42 | module => 'Module::Load::Conditional', |
43 | version => $Module::Load::Conditional::VERSION, |
44 | ); |
45 | |
46 | ok( $rv->{uptodate}, q[Verify self] ); |
3fa779ab |
47 | is( $rv->{version}, $Module::Load::Conditional::VERSION, |
0dc418cb |
48 | q[ Found proper version] ); |
49 | |
3fa779ab |
50 | ### break up the specification |
51 | my @rv_path = do { |
52 | |
53 | ### Use the UNIX specific method, as the VMS one currently |
54 | ### converts the file spec back to VMS format. |
55 | my $class = ON_VMS ? 'File::Spec::Unix' : 'File::Spec'; |
56 | |
57 | my($vol, $path, $file) = $class->splitpath( $rv->{'file'} ); |
fd9d6e12 |
58 | |
3fa779ab |
59 | my @path = ($vol, $class->splitdir( $path ), $file ); |
fd9d6e12 |
60 | |
3fa779ab |
61 | ### First element could be blank for some system types like VMS |
62 | shift @path if $vol eq ''; |
63 | |
64 | ### and return it |
65 | @path; |
66 | }; |
67 | |
68 | is( $INC{'Module/Load/Conditional.pm'}, |
69 | File::Spec::Unix->catfile(@rv_path), |
0dc418cb |
70 | q[ Found proper file] |
71 | ); |
72 | |
73 | } |
74 | |
3fa779ab |
75 | ### the version may contain an _, which means perl will warn about 'not |
76 | ### numeric' -- turn off that warning here. |
77 | { local $^W; |
0dc418cb |
78 | my $rv = check_install( |
79 | module => 'Module::Load::Conditional', |
80 | version => $Module::Load::Conditional::VERSION + 1, |
81 | ); |
82 | |
83 | ok( !$rv->{uptodate} && $rv->{version} && $rv->{file}, |
84 | q[Verify out of date module] |
85 | ); |
86 | } |
87 | |
88 | { |
89 | my $rv = check_install( module => 'Module::Load::Conditional' ); |
90 | |
91 | ok( $rv->{uptodate} && $rv->{version} && $rv->{file}, |
92 | q[Verify any module] |
93 | ); |
94 | } |
95 | |
96 | { |
97 | my $rv = check_install( module => 'Module::Does::Not::Exist' ); |
98 | |
99 | ok( !$rv->{uptodate} && !$rv->{version} && !$rv->{file}, |
100 | q[Verify non-existant module] |
101 | ); |
102 | |
103 | } |
104 | |
e163f9a0 |
105 | ### test finding a version of a module that mentions $VERSION in pod |
106 | { my $rv = check_install( module => 'InPod' ); |
107 | ok( $rv, 'Testing $VERSION in POD' ); |
108 | ok( $rv->{version}, " Version found" ); |
109 | is( $rv->{version}, 2, " Version is correct" ); |
110 | } |
111 | |
3fa779ab |
112 | ### test beta/developer release versions |
113 | { my $test_ver = $Module::Load::Conditional::VERSION; |
114 | |
115 | ### strip beta tags |
116 | $test_ver =~ s/_\d+//g; |
117 | $test_ver .= '_99'; |
118 | |
119 | my $rv = check_install( |
120 | module => 'Module::Load::Conditional', |
121 | version => $test_ver, |
122 | ); |
123 | |
124 | ok( $rv, "Checking beta versions" ); |
125 | ok( !$rv->{'uptodate'}, " Beta version is higher" ); |
126 | |
127 | } |
128 | |
e163f9a0 |
129 | ### test $FIND_VERSION |
0dc418cb |
130 | { local $Module::Load::Conditional::FIND_VERSION = 0; |
131 | local $Module::Load::Conditional::FIND_VERSION = 0; |
132 | |
133 | my $rv = check_install( module => 'Module::Load::Conditional' ); |
134 | |
135 | ok( $rv, 'Testing $FIND_VERSION' ); |
136 | is( $rv->{version}, undef, " No version info returned" ); |
137 | ok( $rv->{uptodate}, " Module marked as uptodate" ); |
138 | } |
139 | |
140 | ### test 'can_load' ### |
141 | |
142 | { |
143 | my $use_list = { 'LoadIt' => 1 }; |
144 | my $bool = can_load( modules => $use_list ); |
145 | |
146 | ok( $bool, q[Load simple module] ); |
147 | } |
148 | |
149 | { |
150 | my $use_list = { 'Commented' => 2 }; |
151 | my $bool = can_load( modules => $use_list ); |
152 | |
153 | ok( $bool, q[Load module with a second, commented-out $VERSION] ); |
154 | } |
155 | |
156 | { |
157 | my $use_list = { 'Must::Be::Loaded' => 1 }; |
158 | my $bool = can_load( modules => $use_list ); |
159 | |
160 | ok( !$bool, q[Detect out of date module] ); |
161 | } |
162 | |
163 | { |
164 | delete $INC{'LoadIt.pm'}; |
165 | delete $INC{'Must/Be/Loaded.pm'}; |
166 | |
167 | my $use_list = { 'LoadIt' => 1, 'Must::Be::Loaded' => 1 }; |
168 | my $bool = can_load( modules => $use_list ); |
169 | |
170 | ok( !$INC{'LoadIt.pm'} && !$INC{'Must/Be/Loaded.pm'}, |
171 | q[Do not load if one prerequisite fails] |
172 | ); |
173 | } |
174 | |
175 | |
176 | ### test 'requires' ### |
1dc5a1cd |
177 | SKIP:{ |
178 | skip "Depends on \$^X, which doesn't work well when testing the Perl core", |
179 | 1 if $ENV{PERL_CORE}; |
0dc418cb |
180 | |
e163f9a0 |
181 | my %list = map { $_ => 1 } requires('Carp'); |
182 | |
0dc418cb |
183 | my $flag; |
184 | $flag++ unless delete $list{'Exporter'}; |
185 | |
186 | ok( !$flag, q[Detecting requirements] ); |
187 | } |
188 | |
0dc418cb |
189 | ### test using the %INC lookup for check_install |
190 | { local $Module::Load::Conditional::CHECK_INC_HASH = 1; |
191 | local $Module::Load::Conditional::CHECK_INC_HASH = 1; |
192 | |
193 | { package A::B::C::D; |
194 | $A::B::C::D::VERSION = $$; |
195 | $INC{'A/B/C/D.pm'} = $$.$$; |
3fa779ab |
196 | |
197 | ### XXX this is no longer needed with M::Load 0.11_01 |
198 | #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS'; |
0dc418cb |
199 | } |
200 | |
201 | my $href = check_install( module => 'A::B::C::D', version => 0 ); |
202 | |
203 | ok( $href, 'Found package in %INC' ); |
204 | is( $href->{'file'}, $$.$$, ' Found correct file' ); |
205 | is( $href->{'version'}, $$, ' Found correct version' ); |
206 | ok( $href->{'uptodate'}, ' Marked as uptodate' ); |
207 | ok( can_load( modules => { 'A::B::C::D' => 0 } ), |
208 | ' can_load successful' ); |
209 | } |
210 | |