This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Subject: [PATCH] Update File::Fetch to 0.18
[perl5.git] / lib / Module / Load / Conditional / t / 01_Module_Load_Conditional.t
CommitLineData
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 14BEGIN { use FindBin; }
0dc418cb
JB
15BEGIN { chdir 't' if -d 't' }
16
17use strict;
0dc418cb 18use File::Spec ();
3fa779ab
JB
19use Test::More 'no_plan';
20
21use constant ON_VMS => $^O eq 'VMS';
0dc418cb 22
3fa779ab
JB
23use lib "$FindBin::Bin/../lib";
24use lib "$FindBin::Bin/to_load";
0dc418cb 25
91e53322 26use_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
JB
48 q[ Found proper version] );
49
3fa779ab
JB
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
JB
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 };
596fddd5
SP
67 my $inc_path = $INC{'Module/Load/Conditional.pm'};
68 if ( $^O eq 'MSWin32' ) {
69 $inc_path = File::Spec->canonpath( $inc_path );
70 $inc_path =~ s{\\}{/}g; # to meet with unix path
71 }
72 is( $inc_path,
3fa779ab 73 File::Spec::Unix->catfile(@rv_path),
0dc418cb
JB
74 q[ Found proper file]
75 );
76
77}
78
3fa779ab
JB
79### the version may contain an _, which means perl will warn about 'not
80### numeric' -- turn off that warning here.
81{ local $^W;
0dc418cb
JB
82 my $rv = check_install(
83 module => 'Module::Load::Conditional',
84 version => $Module::Load::Conditional::VERSION + 1,
85 );
86
87 ok( !$rv->{uptodate} && $rv->{version} && $rv->{file},
88 q[Verify out of date module]
89 );
90}
91
92{
93 my $rv = check_install( module => 'Module::Load::Conditional' );
94
95 ok( $rv->{uptodate} && $rv->{version} && $rv->{file},
96 q[Verify any module]
97 );
98}
99
100{
101 my $rv = check_install( module => 'Module::Does::Not::Exist' );
102
103 ok( !$rv->{uptodate} && !$rv->{version} && !$rv->{file},
104 q[Verify non-existant module]
105 );
106
107}
108
e163f9a0
RGS
109### test finding a version of a module that mentions $VERSION in pod
110{ my $rv = check_install( module => 'InPod' );
111 ok( $rv, 'Testing $VERSION in POD' );
112 ok( $rv->{version}, " Version found" );
113 is( $rv->{version}, 2, " Version is correct" );
114}
115
3fa779ab
JB
116### test beta/developer release versions
117{ my $test_ver = $Module::Load::Conditional::VERSION;
118
119 ### strip beta tags
120 $test_ver =~ s/_\d+//g;
121 $test_ver .= '_99';
122
123 my $rv = check_install(
124 module => 'Module::Load::Conditional',
125 version => $test_ver,
126 );
127
128 ok( $rv, "Checking beta versions" );
129 ok( !$rv->{'uptodate'}, " Beta version is higher" );
130
131}
132
e163f9a0 133### test $FIND_VERSION
0dc418cb
JB
134{ local $Module::Load::Conditional::FIND_VERSION = 0;
135 local $Module::Load::Conditional::FIND_VERSION = 0;
136
137 my $rv = check_install( module => 'Module::Load::Conditional' );
138
139 ok( $rv, 'Testing $FIND_VERSION' );
140 is( $rv->{version}, undef, " No version info returned" );
141 ok( $rv->{uptodate}, " Module marked as uptodate" );
142}
143
144### test 'can_load' ###
145
146{
147 my $use_list = { 'LoadIt' => 1 };
148 my $bool = can_load( modules => $use_list );
149
150 ok( $bool, q[Load simple module] );
151}
152
153{
154 my $use_list = { 'Commented' => 2 };
155 my $bool = can_load( modules => $use_list );
156
157 ok( $bool, q[Load module with a second, commented-out $VERSION] );
158}
159
160{
fc934b13 161 my $use_list = { 'MustBe::Loaded' => 1 };
0dc418cb
JB
162 my $bool = can_load( modules => $use_list );
163
164 ok( !$bool, q[Detect out of date module] );
165}
166
167{
168 delete $INC{'LoadIt.pm'};
fc934b13 169 delete $INC{'MustBe/Loaded.pm'};
0dc418cb 170
fc934b13 171 my $use_list = { 'LoadIt' => 1, 'MustBe::Loaded' => 1 };
0dc418cb
JB
172 my $bool = can_load( modules => $use_list );
173
fc934b13 174 ok( !$INC{'LoadIt.pm'} && !$INC{'MustBe/Loaded.pm'},
0dc418cb
JB
175 q[Do not load if one prerequisite fails]
176 );
177}
178
179
180### test 'requires' ###
1dc5a1cd
SP
181SKIP:{
182 skip "Depends on \$^X, which doesn't work well when testing the Perl core",
183 1 if $ENV{PERL_CORE};
0dc418cb 184
e163f9a0
RGS
185 my %list = map { $_ => 1 } requires('Carp');
186
0dc418cb
JB
187 my $flag;
188 $flag++ unless delete $list{'Exporter'};
189
190 ok( !$flag, q[Detecting requirements] );
191}
192
0dc418cb
JB
193### test using the %INC lookup for check_install
194{ local $Module::Load::Conditional::CHECK_INC_HASH = 1;
195 local $Module::Load::Conditional::CHECK_INC_HASH = 1;
196
197 { package A::B::C::D;
198 $A::B::C::D::VERSION = $$;
199 $INC{'A/B/C/D.pm'} = $$.$$;
3fa779ab
JB
200
201 ### XXX this is no longer needed with M::Load 0.11_01
202 #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS';
0dc418cb
JB
203 }
204
205 my $href = check_install( module => 'A::B::C::D', version => 0 );
206
207 ok( $href, 'Found package in %INC' );
208 is( $href->{'file'}, $$.$$, ' Found correct file' );
209 is( $href->{'version'}, $$, ' Found correct version' );
210 ok( $href->{'uptodate'}, ' Marked as uptodate' );
211 ok( can_load( modules => { 'A::B::C::D' => 0 } ),
212 ' can_load successful' );
213}
214