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