1 ### Module::Load::Conditional test suite ###
2 ### this should no longer be needed
4 # if( $ENV{PERL_CORE} ) {
5 # chdir '../lib/Module/Load/Conditional'
6 # if -d '../lib/Module/Load/Conditional';
7 # unshift @INC, '../../../..';
9 # ### fix perl location too
10 # $^X = '../../../../../t/' . $^X;
14 BEGIN { use FindBin; }
15 BEGIN { chdir 't' if -d 't' }
19 use Test::More 'no_plan';
21 use constant ON_VMS => $^O eq 'VMS';
23 use lib File::Spec->catdir($FindBin::Bin, qw[.. lib] );
24 use lib File::Spec->catdir($FindBin::Bin, q[to_load] );
26 use_ok( 'Module::Load::Conditional' );
28 ### stupid stupid warnings ###
29 { $Module::Load::Conditional::VERBOSE =
30 $Module::Load::Conditional::VERBOSE = 0;
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;
41 my $rv = check_install(
42 module => 'Module::Load::Conditional',
43 version => $Module::Load::Conditional::VERSION,
46 ok( $rv->{uptodate}, q[Verify self] );
47 is( $rv->{version}, $Module::Load::Conditional::VERSION,
48 q[ Found proper version] );
49 ok( $rv->{dir}, q[ Found directory information] );
51 { my $dir = File::Spec->canonpath( $rv->{dir} );
53 ### special rules apply on VMS, as always...
55 ### Need path syntax for VMS compares.
56 $dir = VMS::Filespec::pathify($dir);
57 ### Remove the trailing VMS specific directory delimiter
61 ### quote for Win32 paths, use | to avoid slash confusion
62 my $dir_re = qr|^\Q$dir\E|i;
63 like( File::Spec->canonpath( $rv->{file} ), $dir_re,
64 q[ Dir subset of file path] );
67 ### break up the specification
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';
74 my($vol, $path, $file) = $class->splitpath( $rv->{'file'} );
76 my @path = ($vol, $class->splitdir( $path ), $file );
78 ### First element could be blank for some system types like VMS
79 shift @path if $vol eq '';
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
90 File::Spec::Unix->catfile(@rv_path),
98 ### the version may contain an _, which means perl will warn about 'not
99 ### numeric' -- turn off that warning here.
101 my $rv = check_install(
102 module => 'Module::Load::Conditional',
103 version => $Module::Load::Conditional::VERSION + 1,
106 ok( !$rv->{uptodate} && $rv->{version} && $rv->{file},
107 q[Verify out of date module]
112 my $rv = check_install( module => 'Module::Load::Conditional' );
114 ok( $rv->{uptodate} && $rv->{version} && $rv->{file},
120 my $rv = check_install( module => 'Module::Does::Not::Exist' );
122 ok( !$rv->{uptodate} && !$rv->{version} && !$rv->{file},
123 q[Verify non-existant module]
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" );
135 ### test beta/developer release versions
136 { my $test_ver = $Module::Load::Conditional::VERSION;
139 $test_ver =~ s/_\d+//g;
142 my $rv = check_install(
143 module => 'Module::Load::Conditional',
144 version => $test_ver,
147 ok( $rv, "Checking beta versions" );
148 ok( !$rv->{'uptodate'}, " Beta version is higher" );
152 ### test $FIND_VERSION
153 { local $Module::Load::Conditional::FIND_VERSION = 0;
154 local $Module::Load::Conditional::FIND_VERSION = 0;
156 my $rv = check_install( module => 'Module::Load::Conditional' );
158 ok( $rv, 'Testing $FIND_VERSION' );
159 is( $rv->{version}, undef, " No version info returned" );
160 ok( $rv->{uptodate}, " Module marked as uptodate" );
163 ### test 'can_load' ###
166 my $use_list = { 'LoadIt' => 1 };
167 my $bool = can_load( modules => $use_list );
169 ok( $bool, q[Load simple module] );
173 my $use_list = { 'Commented' => 2 };
174 my $bool = can_load( modules => $use_list );
176 ok( $bool, q[Load module with a second, commented-out $VERSION] );
180 my $use_list = { 'MustBe::Loaded' => 1 };
181 my $bool = can_load( modules => $use_list );
183 ok( !$bool, q[Detect out of date module] );
187 delete $INC{'LoadIt.pm'};
188 delete $INC{'MustBe/Loaded.pm'};
190 my $use_list = { 'LoadIt' => 1, 'MustBe::Loaded' => 1 };
191 my $bool = can_load( modules => $use_list );
193 ok( !$INC{'LoadIt.pm'} && !$INC{'MustBe/Loaded.pm'},
194 q[Do not load if one prerequisite fails]
199 ### test 'requires' ###
201 skip "Depends on \$^X, which doesn't work well when testing the Perl core",
202 1 if $ENV{PERL_CORE};
204 my %list = map { $_ => 1 } requires('Carp');
207 $flag++ unless delete $list{'Exporter'};
209 ok( !$flag, q[Detecting requirements] );
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;
216 { package A::B::C::D;
217 $A::B::C::D::VERSION = $$;
218 $INC{'A/B/C/D.pm'} = $$.$$;
220 ### XXX this is no longer needed with M::Load 0.11_01
221 #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS';
224 my $href = check_install( module => 'A::B::C::D', version => 0 );
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' );