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