4 if( $ENV{PERL_CORE} ) {
9 unshift @INC, 't/lib/';
24 use Test::More tests => 42;
26 BEGIN { use_ok( 'ExtUtils::Installed' ) }
28 my $mandirs = !!$Config{man1direxp} + !!$Config{man3direxp};
30 # saves having to qualify package name for class methods
31 my $ei = bless( {}, 'ExtUtils::Installed' );
34 ok( $ei->_is_prefix('foo/bar', 'foo'),
35 '_is_prefix() should match valid path prefix' );
36 ok( !$ei->_is_prefix('\foo\bar', '\bar'),
37 '... should not match wrong prefix' );
40 ok( $ei->_is_type(0, 'all'), '_is_type() should be true for type of "all"' );
42 foreach my $path (qw( man1dir man3dir )) {
44 my $dir = $Config{$path.'exp'};
45 skip("no man directory $path on this system", 2 ) unless $dir;
47 my $file = $dir . '/foo';
48 ok( $ei->_is_type($file, 'doc'), "... should find doc file in $path" );
49 ok( !$ei->_is_type($file, 'prog'), "... but not prog file in $path" );
53 # VMS 5.6.1 doesn't seem to have $Config{prefixexp}
54 my $prefix = $Config{prefix} || $Config{prefixexp};
56 # You can concatenate /foo but not foo:, which defaults in the current
58 $prefix = VMS::Filespec::unixify($prefix) if $^O eq 'VMS';
60 # ActivePerl 5.6.1/631 has $Config{prefixexp} as 'p:' for some reason
61 $prefix = $Config{prefix} if $prefix eq 'p:' && $^O eq 'MSWin32';
63 ok( $ei->_is_type( File::Spec->catfile($prefix, 'bar'), 'prog'),
64 "... should find prog file under $prefix" );
67 skip('no man directories on this system', 1) unless $mandirs;
68 is( $ei->_is_type('bar', 'doc'), 0,
69 '... should not find doc file outside path' );
72 ok( !$ei->_is_type('bar', 'prog'),
73 '... nor prog file outside path' );
74 ok( !$ei->_is_type('whocares', 'someother'), '... nor other type anywhere' );
77 ok( $ei->_is_under('foo'), '_is_under() should return true with no dirs' );
79 my @under = qw( boo bar baz );
80 ok( !$ei->_is_under('foo', @under), '... should find no file not under dirs');
81 ok( $ei->_is_under('baz', @under), '... should find file under dir' );
84 my $realei = ExtUtils::Installed->new();
86 isa_ok( $realei, 'ExtUtils::Installed' );
87 isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' );
88 is( $realei->{Perl}{version}, $Config{version},
89 'new() should set Perl version from %Config' );
92 if (mkpath('auto/FakeMod')) {
93 if (open(PACKLIST, '>', 'auto/FakeMod/.packlist')) {
94 print PACKLIST 'list';
96 if (open(FAKEMOD, '>', 'auto/FakeMod/FakeMod.pm')) {
97 print FAKEMOD <<'FAKE';
99 use vars qw( $VERSION );
112 skip("could not write packlist: $!", 3 ) unless $wrotelist;
114 # avoid warning and death by localizing glob
115 local *ExtUtils::Installed::Config;
116 my $fake_mod_dir = File::Spec->catdir(cwd(), 'auto', 'FakeMod');
117 %ExtUtils::Installed::Config = (
119 sitearchexp => $fake_mod_dir,
122 # necessary to fool new()
123 push @INC, $fake_mod_dir;
125 my $realei = ExtUtils::Installed->new();
126 ok( exists $realei->{FakeMod}, 'new() should find modules with .packlists');
127 isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' );
128 is( $realei->{FakeMod}{version}, '1.1.1',
129 '... should find version in modules' );
133 $ei->{$_} = 1 for qw( abc def ghi );
134 is( join(' ', $ei->modules()), 'abc def ghi',
135 'modules() should return sorted keys' );
140 ($Config{man1direxp} ?
141 (File::Spec->catdir($Config{man1direxp}, 'foo') => 1) :
143 ($Config{man3direxp} ?
144 (File::Spec->catdir($Config{man3direxp}, 'bar') => 1) :
146 File::Spec->catdir($prefix, 'foobar') => 1,
151 eval { $ei->files('badmod') };
152 like( $@, qr/badmod is not installed/,'files() should croak given bad modname');
153 eval { $ei->files('goodmod', 'badtype' ) };
154 like( $@, qr/type must be/,'files() should croak given bad type' );
158 skip('no man directory man1dir on this system', 2)
159 unless $Config{man1direxp};
160 @files = $ei->files('goodmod', 'doc', $Config{man1direxp});
161 is( scalar @files, 1, '... should find doc file under given dir' );
162 is( grep({ /foo$/ } @files), 1, '... checking file name' );
165 skip('no man directories on this system', 1) unless $mandirs;
166 @files = $ei->files('goodmod', 'doc');
167 is( scalar @files, $mandirs, '... should find all doc files with no dir' );
170 @files = $ei->files('goodmod', 'prog', 'fake', 'fake2');
171 is( scalar @files, 0, '... should find no doc files given wrong dirs' );
172 @files = $ei->files('goodmod', 'prog');
173 is( scalar @files, 1, '... should find doc file in correct dir' );
174 like( $files[0], qr/foobar[>\]]?$/, '... checking file name' );
175 @files = $ei->files('goodmod');
176 is( scalar @files, 2 + $mandirs, '... should find all files with no type specified' );
177 my %dirnames = map { lc($_) => dirname($_) } @files;
180 my @dirs = $ei->directories('goodmod', 'prog', 'fake');
181 is( scalar @dirs, 0, 'directories() should return no dirs if no files found' );
184 skip('no man directories on this system', 1) unless $mandirs;
185 @dirs = $ei->directories('goodmod', 'doc');
186 is( scalar @dirs, $mandirs, '... should find all files files() would' );
188 @dirs = $ei->directories('goodmod');
189 is( scalar @dirs, 2 + $mandirs, '... should find all files files() would, again' );
190 @files = sort map { exists $dirnames{lc($_)} ? $dirnames{lc($_)} : '' } @files;
191 is( join(' ', @files), join(' ', @dirs), '... should sort output' );
196 (dirname($Config{man1direxp}) eq dirname($Config{man3direxp}))
200 skip('no man directories on this system', 1) unless $mandirs;
201 @dirs = $ei->directory_tree('goodmod', 'doc', $Config{man1direxp} ?
202 dirname($Config{man1direxp}) : dirname($Config{man3direxp}));
203 is( scalar @dirs, $expectdirs,
204 'directory_tree() should report intermediate dirs to those requested' );
207 my $fakepak = Fakepak->new(102);
211 packlist => $fakepak,
214 # these should all croak
215 foreach my $sub (qw( validate packlist version )) {
216 eval { $ei->$sub('nomod') };
217 like( $@, qr/nomod is not installed/,
218 "$sub() should croak when asked about uninstalled module" );
222 is( $ei->validate('yesmod'), 'validated',
223 'validate() should return results of packlist validate() call' );
226 is( ${ $ei->packlist('yesmod') }, 102,
227 'packlist() should report installed mod packlist' );
230 is( $ei->version('yesmod'), 101,
231 'version() should report installed mod version' );
235 for my $file (qw( .packlist FakePak.pm )) {
236 1 while unlink $file;
238 File::Path::rmtree('auto') or warn "Couldn't rmtree auto: $!";
246 bless(\(my $scalar = shift), $class);