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 | |
c259ebfb |
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 | |
9b31c40c |
23 | use lib File::Spec->catdir($FindBin::Bin, qw[.. lib] ); |
24 | use lib File::Spec->catdir($FindBin::Bin, q[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] ); |
9b31c40c |
49 | ok( $rv->{dir}, q[ Found directory information] ); |
50 | |
687d0cf8 |
51 | { my $dir = File::Spec->canonpath( $rv->{dir} ); |
b8a4246c |
52 | |
53 | ### special rules apply on VMS, as always... |
54 | if (ON_VMS) { |
55 | ### Need path syntax for VMS compares. |
56 | $dir = VMS::Filespec::pathify($dir); |
57 | ### Remove the trailing VMS specific directory delimiter |
58 | $dir =~ s/\]//; |
59 | } |
60 | |
61 | ### quote for Win32 paths, use | to avoid slash confusion |
62 | my $dir_re = qr|^\Q$dir\E|i; |
687d0cf8 |
63 | like( File::Spec->canonpath( $rv->{file} ), $dir_re, |
9b31c40c |
64 | q[ Dir subset of file path] ); |
65 | } |
0dc418cb |
66 | |
3fa779ab |
67 | ### break up the specification |
68 | my @rv_path = do { |
69 | |
70 | ### Use the UNIX specific method, as the VMS one currently |
71 | ### converts the file spec back to VMS format. |
72 | my $class = ON_VMS ? 'File::Spec::Unix' : 'File::Spec'; |
73 | |
74 | my($vol, $path, $file) = $class->splitpath( $rv->{'file'} ); |
fd9d6e12 |
75 | |
3fa779ab |
76 | my @path = ($vol, $class->splitdir( $path ), $file ); |
fd9d6e12 |
77 | |
3fa779ab |
78 | ### First element could be blank for some system types like VMS |
79 | shift @path if $vol eq ''; |
80 | |
81 | ### and return it |
82 | @path; |
83 | }; |
596fddd5 |
84 | my $inc_path = $INC{'Module/Load/Conditional.pm'}; |
85 | if ( $^O eq 'MSWin32' ) { |
86 | $inc_path = File::Spec->canonpath( $inc_path ); |
87 | $inc_path =~ s{\\}{/}g; # to meet with unix path |
88 | } |
89 | is( $inc_path, |
3fa779ab |
90 | File::Spec::Unix->catfile(@rv_path), |
0dc418cb |
91 | q[ Found proper file] |
92 | ); |
9b31c40c |
93 | |
94 | |
0dc418cb |
95 | |
96 | } |
97 | |
3fa779ab |
98 | ### the version may contain an _, which means perl will warn about 'not |
99 | ### numeric' -- turn off that warning here. |
100 | { local $^W; |
0dc418cb |
101 | my $rv = check_install( |
102 | module => 'Module::Load::Conditional', |
103 | version => $Module::Load::Conditional::VERSION + 1, |
104 | ); |
105 | |
106 | ok( !$rv->{uptodate} && $rv->{version} && $rv->{file}, |
107 | q[Verify out of date module] |
108 | ); |
109 | } |
110 | |
111 | { |
112 | my $rv = check_install( module => 'Module::Load::Conditional' ); |
113 | |
114 | ok( $rv->{uptodate} && $rv->{version} && $rv->{file}, |
115 | q[Verify any module] |
116 | ); |
117 | } |
118 | |
119 | { |
120 | my $rv = check_install( module => 'Module::Does::Not::Exist' ); |
121 | |
122 | ok( !$rv->{uptodate} && !$rv->{version} && !$rv->{file}, |
123 | q[Verify non-existant module] |
124 | ); |
125 | |
126 | } |
127 | |
e163f9a0 |
128 | ### test finding a version of a module that mentions $VERSION in pod |
129 | { my $rv = check_install( module => 'InPod' ); |
130 | ok( $rv, 'Testing $VERSION in POD' ); |
131 | ok( $rv->{version}, " Version found" ); |
132 | is( $rv->{version}, 2, " Version is correct" ); |
133 | } |
134 | |
3fa779ab |
135 | ### test beta/developer release versions |
136 | { my $test_ver = $Module::Load::Conditional::VERSION; |
137 | |
138 | ### strip beta tags |
139 | $test_ver =~ s/_\d+//g; |
140 | $test_ver .= '_99'; |
141 | |
142 | my $rv = check_install( |
143 | module => 'Module::Load::Conditional', |
144 | version => $test_ver, |
145 | ); |
146 | |
147 | ok( $rv, "Checking beta versions" ); |
148 | ok( !$rv->{'uptodate'}, " Beta version is higher" ); |
149 | |
150 | } |
151 | |
e163f9a0 |
152 | ### test $FIND_VERSION |
0dc418cb |
153 | { local $Module::Load::Conditional::FIND_VERSION = 0; |
154 | local $Module::Load::Conditional::FIND_VERSION = 0; |
155 | |
156 | my $rv = check_install( module => 'Module::Load::Conditional' ); |
157 | |
158 | ok( $rv, 'Testing $FIND_VERSION' ); |
159 | is( $rv->{version}, undef, " No version info returned" ); |
160 | ok( $rv->{uptodate}, " Module marked as uptodate" ); |
161 | } |
162 | |
163 | ### test 'can_load' ### |
164 | |
165 | { |
166 | my $use_list = { 'LoadIt' => 1 }; |
167 | my $bool = can_load( modules => $use_list ); |
168 | |
169 | ok( $bool, q[Load simple module] ); |
170 | } |
171 | |
172 | { |
173 | my $use_list = { 'Commented' => 2 }; |
174 | my $bool = can_load( modules => $use_list ); |
175 | |
176 | ok( $bool, q[Load module with a second, commented-out $VERSION] ); |
177 | } |
178 | |
179 | { |
fc934b13 |
180 | my $use_list = { 'MustBe::Loaded' => 1 }; |
0dc418cb |
181 | my $bool = can_load( modules => $use_list ); |
182 | |
183 | ok( !$bool, q[Detect out of date module] ); |
184 | } |
185 | |
186 | { |
187 | delete $INC{'LoadIt.pm'}; |
fc934b13 |
188 | delete $INC{'MustBe/Loaded.pm'}; |
0dc418cb |
189 | |
fc934b13 |
190 | my $use_list = { 'LoadIt' => 1, 'MustBe::Loaded' => 1 }; |
0dc418cb |
191 | my $bool = can_load( modules => $use_list ); |
192 | |
fc934b13 |
193 | ok( !$INC{'LoadIt.pm'} && !$INC{'MustBe/Loaded.pm'}, |
0dc418cb |
194 | q[Do not load if one prerequisite fails] |
195 | ); |
196 | } |
197 | |
198 | |
199 | ### test 'requires' ### |
1dc5a1cd |
200 | SKIP:{ |
201 | skip "Depends on \$^X, which doesn't work well when testing the Perl core", |
202 | 1 if $ENV{PERL_CORE}; |
0dc418cb |
203 | |
e163f9a0 |
204 | my %list = map { $_ => 1 } requires('Carp'); |
205 | |
0dc418cb |
206 | my $flag; |
207 | $flag++ unless delete $list{'Exporter'}; |
208 | |
209 | ok( !$flag, q[Detecting requirements] ); |
210 | } |
211 | |
0dc418cb |
212 | ### test using the %INC lookup for check_install |
213 | { local $Module::Load::Conditional::CHECK_INC_HASH = 1; |
214 | local $Module::Load::Conditional::CHECK_INC_HASH = 1; |
215 | |
216 | { package A::B::C::D; |
217 | $A::B::C::D::VERSION = $$; |
218 | $INC{'A/B/C/D.pm'} = $$.$$; |
3fa779ab |
219 | |
220 | ### XXX this is no longer needed with M::Load 0.11_01 |
221 | #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS'; |
0dc418cb |
222 | } |
223 | |
224 | my $href = check_install( module => 'A::B::C::D', version => 0 ); |
225 | |
226 | ok( $href, 'Found package in %INC' ); |
227 | is( $href->{'file'}, $$.$$, ' Found correct file' ); |
228 | is( $href->{'version'}, $$, ' Found correct version' ); |
229 | ok( $href->{'uptodate'}, ' Marked as uptodate' ); |
230 | ok( can_load( modules => { 'A::B::C::D' => 0 } ), |
231 | ' can_load successful' ); |
232 | } |
233 | |