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 "$FindBin::Bin/../lib";
24 use lib "$FindBin::Bin/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] );
50 ### break up the specification
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';
57 my($vol, $path, $file) = $class->splitpath( $rv->{'file'} );
59 my @path = ($vol, $class->splitdir( $path ), $file );
61 ### First element could be blank for some system types like VMS
62 shift @path if $vol eq '';
68 is( $INC{'Module/Load/Conditional.pm'},
69 File::Spec::Unix->catfile(@rv_path),
75 ### the version may contain an _, which means perl will warn about 'not
76 ### numeric' -- turn off that warning here.
78 my $rv = check_install(
79 module => 'Module::Load::Conditional',
80 version => $Module::Load::Conditional::VERSION + 1,
83 ok( !$rv->{uptodate} && $rv->{version} && $rv->{file},
84 q[Verify out of date module]
89 my $rv = check_install( module => 'Module::Load::Conditional' );
91 ok( $rv->{uptodate} && $rv->{version} && $rv->{file},
97 my $rv = check_install( module => 'Module::Does::Not::Exist' );
99 ok( !$rv->{uptodate} && !$rv->{version} && !$rv->{file},
100 q[Verify non-existant module]
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" );
112 ### test beta/developer release versions
113 { my $test_ver = $Module::Load::Conditional::VERSION;
116 $test_ver =~ s/_\d+//g;
119 my $rv = check_install(
120 module => 'Module::Load::Conditional',
121 version => $test_ver,
124 ok( $rv, "Checking beta versions" );
125 ok( !$rv->{'uptodate'}, " Beta version is higher" );
129 ### test $FIND_VERSION
130 { local $Module::Load::Conditional::FIND_VERSION = 0;
131 local $Module::Load::Conditional::FIND_VERSION = 0;
133 my $rv = check_install( module => 'Module::Load::Conditional' );
135 ok( $rv, 'Testing $FIND_VERSION' );
136 is( $rv->{version}, undef, " No version info returned" );
137 ok( $rv->{uptodate}, " Module marked as uptodate" );
140 ### test 'can_load' ###
143 my $use_list = { 'LoadIt' => 1 };
144 my $bool = can_load( modules => $use_list );
146 ok( $bool, q[Load simple module] );
150 my $use_list = { 'Commented' => 2 };
151 my $bool = can_load( modules => $use_list );
153 ok( $bool, q[Load module with a second, commented-out $VERSION] );
157 my $use_list = { 'MustBe::Loaded' => 1 };
158 my $bool = can_load( modules => $use_list );
160 ok( !$bool, q[Detect out of date module] );
164 delete $INC{'LoadIt.pm'};
165 delete $INC{'MustBe/Loaded.pm'};
167 my $use_list = { 'LoadIt' => 1, 'MustBe::Loaded' => 1 };
168 my $bool = can_load( modules => $use_list );
170 ok( !$INC{'LoadIt.pm'} && !$INC{'MustBe/Loaded.pm'},
171 q[Do not load if one prerequisite fails]
176 ### test 'requires' ###
178 skip "Depends on \$^X, which doesn't work well when testing the Perl core",
179 1 if $ENV{PERL_CORE};
181 my %list = map { $_ => 1 } requires('Carp');
184 $flag++ unless delete $list{'Exporter'};
186 ok( !$flag, q[Detecting requirements] );
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;
193 { package A::B::C::D;
194 $A::B::C::D::VERSION = $$;
195 $INC{'A/B/C/D.pm'} = $$.$$;
197 ### XXX this is no longer needed with M::Load 0.11_01
198 #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS';
201 my $href = check_install( module => 'A::B::C::D', version => 0 );
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' );