4 unshift @INC, 't/lib/';
7 my $Is_VMS = $^O eq 'VMS';
17 use Test::More tests => 63;
19 BEGIN { use_ok( 'ExtUtils::Installed' ) }
21 my $mandirs = !!$Config{man1direxp} + !!$Config{man3direxp};
23 # saves having to qualify package name for class methods
24 my $ei = bless( {}, 'ExtUtils::Installed' );
26 # Make sure meta info is available
27 $ei->{':private:'}{Config} = \%Config;
28 $ei->{':private:'}{INC} = \@INC;
31 ok( $ei->_is_prefix('foo/bar', 'foo'),
32 '_is_prefix() should match valid path prefix' );
33 ok( !$ei->_is_prefix('\foo\bar', '\bar'),
34 '... should not match wrong prefix' );
37 ok( $ei->_is_type(0, 'all'), '_is_type() should be true for type of "all"' );
39 foreach my $path (qw( man1dir man3dir )) {
41 my $dir = File::Spec->canonpath($Config{$path.'exp'});
42 skip("no man directory $path on this system", 2 ) unless $dir;
44 my $file = $dir . '/foo';
45 ok( $ei->_is_type($file, 'doc'), "... should find doc file in $path" );
46 ok( !$ei->_is_type($file, 'prog'), "... but not prog file in $path" );
50 # VMS 5.6.1 doesn't seem to have $Config{prefixexp}
51 my $prefix = $Config{prefix} || $Config{prefixexp};
53 # You can concatenate /foo but not foo:, which defaults in the current
55 $prefix = VMS::Filespec::unixify($prefix) if $Is_VMS;
57 # ActivePerl 5.6.1/631 has $Config{prefixexp} as 'p:' for some reason
58 $prefix = $Config{prefix} if $prefix eq 'p:' && $^O eq 'MSWin32';
60 ok( $ei->_is_type( File::Spec->catfile($prefix, 'bar'), 'prog'),
61 "... should find prog file under $prefix" );
64 skip('no man directories on this system', 1) unless $mandirs;
65 is( $ei->_is_type('bar', 'doc'), 0,
66 '... should not find doc file outside path' );
69 ok( !$ei->_is_type('bar', 'prog'),
70 '... nor prog file outside path' );
71 ok( !$ei->_is_type('whocares', 'someother'), '... nor other type anywhere' );
74 ok( $ei->_is_under('foo'), '_is_under() should return true with no dirs' );
76 my @under = qw( boo bar baz );
77 ok( !$ei->_is_under('foo', @under), '... should find no file not under dirs');
78 ok( $ei->_is_under('baz', @under), '... should find file under dir' );
81 rmtree 'auto/FakeMod';
82 ok( mkpath('auto/FakeMod') );
85 ok(open(PACKLIST, '>auto/FakeMod/.packlist'));
86 print PACKLIST 'list';
89 ok(open(FAKEMOD, '>auto/FakeMod/FakeMod.pm'));
91 print FAKEMOD <<'FAKE';
93 use vars qw( $VERSION );
100 my $fake_mod_dir = File::Spec->catdir(cwd(), 'auto', 'FakeMod');
102 # avoid warning and death by localizing glob
103 local *ExtUtils::Installed::Config;
104 %ExtUtils::Installed::Config = (
107 sitearchexp => $fake_mod_dir,
110 # necessary to fool new()
111 push @INC, $fake_mod_dir;
113 my $realei = ExtUtils::Installed->new();
114 isa_ok( $realei, 'ExtUtils::Installed' );
115 isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' );
116 is( $realei->{Perl}{version}, $Config{version},
117 'new() should set Perl version from %Config' );
119 ok( exists $realei->{FakeMod}, 'new() should find modules with .packlists');
120 isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' );
121 is( $realei->{FakeMod}{version}, '1.1.1',
122 '... should find version in modules' );
125 # Now try this using PERL5LIB
127 local $ENV{PERL5LIB} = join $Config{path_sep}, $fake_mod_dir;
128 local *ExtUtils::Installed::Config;
129 %ExtUtils::Installed::Config = (
132 sitearchexp => cwd(),
135 my $realei = ExtUtils::Installed->new();
136 isa_ok( $realei, 'ExtUtils::Installed' );
137 isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' );
138 is( $realei->{Perl}{version}, $Config{version},
139 'new() should set Perl version from %Config' );
141 ok( exists $realei->{FakeMod},
142 'new() should find modules with .packlists using PERL5LIB'
144 isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' );
145 is( $realei->{FakeMod}{version}, '1.1.1',
146 '... should find version in modules' );
149 # Do the same thing as the last block, but with overrides for
152 my $config_override = { %Config::Config };
153 $config_override->{archlibexp} = cwd();
154 $config_override->{sitearchexp} = $fake_mod_dir;
155 $config_override->{version} = 'fake_test_version';
157 my @inc_override = (@INC, $fake_mod_dir);
159 my $realei = ExtUtils::Installed->new(
160 'config_override' => $config_override,
161 'inc_override' => \@inc_override,
163 isa_ok( $realei, 'ExtUtils::Installed' );
164 isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' );
165 is( $realei->{Perl}{version}, 'fake_test_version',
166 'new(config_override => HASH) overrides %Config' );
168 ok( exists $realei->{FakeMod}, 'new() with overrides should find modules with .packlists');
169 isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' );
170 is( $realei->{FakeMod}{version}, '1.1.1',
171 '... should find version in modules' );
174 # Check if extra_libs works.
176 my $realei = ExtUtils::Installed->new(
177 'extra_libs' => [ cwd() ],
179 isa_ok( $realei, 'ExtUtils::Installed' );
180 isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' );
181 ok( exists $realei->{FakeMod},
182 'new() with extra_libs should find modules with .packlists');
184 #{ use Data::Dumper; local $realei->{':private:'}{Config};
185 # warn Dumper($realei); }
187 isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' );
188 is( $realei->{FakeMod}{version}, '1.1.1',
189 '... should find version in modules' );
193 $ei->{$_} = 1 for qw( abc def ghi );
194 is( join(' ', $ei->modules()), 'abc def ghi',
195 'modules() should return sorted keys' );
197 # This didn't work for a long time due to a sort in scalar context oddity.
198 is( $ei->modules, 3, 'modules() in scalar context' );
203 ($Config{man1direxp} ?
204 (File::Spec->catdir($Config{man1direxp}, 'foo') => 1) :
206 ($Config{man3direxp} ?
207 (File::Spec->catdir($Config{man3direxp}, 'bar') => 1) :
209 File::Spec->catdir($prefix, 'foobar') => 1,
214 eval { $ei->files('badmod') };
215 like( $@, qr/badmod is not installed/,'files() should croak given bad modname');
216 eval { $ei->files('goodmod', 'badtype' ) };
217 like( $@, qr/type must be/,'files() should croak given bad type' );
221 skip('no man directory man1dir on this system', 2)
222 unless $Config{man1direxp};
223 @files = $ei->files('goodmod', 'doc', $Config{man1direxp});
224 is( scalar @files, 1, '... should find doc file under given dir' );
225 is( (grep { /foo$/ } @files), 1, '... checking file name' );
228 skip('no man directories on this system', 1) unless $mandirs;
229 @files = $ei->files('goodmod', 'doc');
230 is( scalar @files, $mandirs, '... should find all doc files with no dir' );
233 @files = $ei->files('goodmod', 'prog', 'fake', 'fake2');
234 is( scalar @files, 0, '... should find no doc files given wrong dirs' );
235 @files = $ei->files('goodmod', 'prog');
236 is( scalar @files, 1, '... should find doc file in correct dir' );
237 like( $files[0], qr/foobar[>\]]?$/, '... checking file name' );
238 @files = $ei->files('goodmod');
239 is( scalar @files, 2 + $mandirs, '... should find all files with no type specified' );
240 my %dirnames = map { lc($_) => dirname($_) } @files;
243 my @dirs = $ei->directories('goodmod', 'prog', 'fake');
244 is( scalar @dirs, 0, 'directories() should return no dirs if no files found' );
247 skip('no man directories on this system', 1) unless $mandirs;
248 @dirs = $ei->directories('goodmod', 'doc');
249 is( scalar @dirs, $mandirs, '... should find all files files() would' );
251 @dirs = $ei->directories('goodmod');
252 is( scalar @dirs, 2 + $mandirs, '... should find all files files() would, again' );
253 @files = sort map { exists $dirnames{lc($_)} ? $dirnames{lc($_)} : '' } @files;
254 is( join(' ', @files), join(' ', @dirs), '... should sort output' );
259 (dirname($Config{man1direxp}) eq dirname($Config{man3direxp}))
263 skip('no man directories on this system', 1) unless $mandirs;
264 @dirs = $ei->directory_tree('goodmod', 'doc', $Config{man1direxp} ?
265 dirname($Config{man1direxp}) : dirname($Config{man3direxp}));
266 is( scalar @dirs, $expectdirs,
267 'directory_tree() should report intermediate dirs to those requested' );
270 my $fakepak = Fakepak->new(102);
274 packlist => $fakepak,
277 # these should all croak
278 foreach my $sub (qw( validate packlist version )) {
279 eval { $ei->$sub('nomod') };
280 like( $@, qr/nomod is not installed/,
281 "$sub() should croak when asked about uninstalled module" );
285 is( $ei->validate('yesmod'), 'validated',
286 'validate() should return results of packlist validate() call' );
289 is( ${ $ei->packlist('yesmod') }, 102,
290 'packlist() should report installed mod packlist' );
293 is( $ei->version('yesmod'), 101,
294 'version() should report installed mod version' );
301 bless(\(my $scalar = shift), $class);