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