4 if( $ENV{PERL_CORE} ) {
9 unshift @INC, 't/lib/';
23 use Test::More tests => 45;
25 BEGIN { use_ok( 'ExtUtils::Installed' ) }
27 my $mandirs = !!$Config{man1direxp} + !!$Config{man3direxp};
29 # saves having to qualify package name for class methods
30 my $ei = bless( {}, 'ExtUtils::Installed' );
33 ok( $ei->_is_prefix('foo/bar', 'foo'),
34 '_is_prefix() should match valid path prefix' );
35 ok( !$ei->_is_prefix('\foo\bar', '\bar'),
36 '... should not match wrong prefix' );
39 ok( $ei->_is_type(0, 'all'), '_is_type() should be true for type of "all"' );
41 foreach my $path (qw( man1dir man3dir )) {
43 my $dir = $Config{$path.'exp'};
44 skip("no man directory $path on this system", 2 ) unless $dir;
46 my $file = $dir . '/foo';
47 ok( $ei->_is_type($file, 'doc'), "... should find doc file in $path" );
48 ok( !$ei->_is_type($file, 'prog'), "... but not prog file in $path" );
52 # VMS 5.6.1 doesn't seem to have $Config{prefixexp}
53 my $prefix = $Config{prefix} || $Config{prefixexp};
55 # You can concatenate /foo but not foo:, which defaults in the current
57 $prefix = VMS::Filespec::unixify($prefix) if $^O eq 'VMS';
59 # ActivePerl 5.6.1/631 has $Config{prefixexp} as 'p:' for some reason
60 $prefix = $Config{prefix} if $prefix eq 'p:' && $^O eq 'MSWin32';
62 ok( $ei->_is_type( File::Spec->catfile($prefix, 'bar'), 'prog'),
63 "... should find prog file under $prefix" );
66 skip('no man directories on this system', 1) unless $mandirs;
67 is( $ei->_is_type('bar', 'doc'), 0,
68 '... should not find doc file outside path' );
71 ok( !$ei->_is_type('bar', 'prog'),
72 '... nor prog file outside path' );
73 ok( !$ei->_is_type('whocares', 'someother'), '... nor other type anywhere' );
76 ok( $ei->_is_under('foo'), '_is_under() should return true with no dirs' );
78 my @under = qw( boo bar baz );
79 ok( !$ei->_is_under('foo', @under), '... should find no file not under dirs');
80 ok( $ei->_is_under('baz', @under), '... should find file under dir' );
84 ok(mkpath('auto/FakeMod'));
85 END { rmtree 'auto/FakeMod' }
87 ok(open(PACKLIST, '>auto/FakeMod/.packlist'));
88 print PACKLIST 'list';
91 ok(open(FAKEMOD, '>auto/FakeMod/FakeMod.pm'));
93 print FAKEMOD <<'FAKE';
95 use vars qw( $VERSION );
103 # avoid warning and death by localizing glob
104 local *ExtUtils::Installed::Config;
105 my $fake_mod_dir = File::Spec->catdir(cwd(), 'auto', 'FakeMod');
106 %ExtUtils::Installed::Config = (
109 sitearchexp => $fake_mod_dir,
112 # necessary to fool new()
113 push @INC, $fake_mod_dir;
115 my $realei = ExtUtils::Installed->new();
116 isa_ok( $realei, 'ExtUtils::Installed' );
117 isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' );
118 is( $realei->{Perl}{version}, $Config{version},
119 'new() should set Perl version from %Config' );
121 ok( exists $realei->{FakeMod}, 'new() should find modules with .packlists');
122 isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' );
123 is( $realei->{FakeMod}{version}, '1.1.1',
124 '... should find version in modules' );
128 $ei->{$_} = 1 for qw( abc def ghi );
129 is( join(' ', $ei->modules()), 'abc def ghi',
130 'modules() should return sorted keys' );
135 ($Config{man1direxp} ?
136 (File::Spec->catdir($Config{man1direxp}, 'foo') => 1) :
138 ($Config{man3direxp} ?
139 (File::Spec->catdir($Config{man3direxp}, 'bar') => 1) :
141 File::Spec->catdir($prefix, 'foobar') => 1,
146 eval { $ei->files('badmod') };
147 like( $@, qr/badmod is not installed/,'files() should croak given bad modname');
148 eval { $ei->files('goodmod', 'badtype' ) };
149 like( $@, qr/type must be/,'files() should croak given bad type' );
153 skip('no man directory man1dir on this system', 2)
154 unless $Config{man1direxp};
155 @files = $ei->files('goodmod', 'doc', $Config{man1direxp});
156 is( scalar @files, 1, '... should find doc file under given dir' );
157 is( (grep { /foo$/ } @files), 1, '... checking file name' );
160 skip('no man directories on this system', 1) unless $mandirs;
161 @files = $ei->files('goodmod', 'doc');
162 is( scalar @files, $mandirs, '... should find all doc files with no dir' );
165 @files = $ei->files('goodmod', 'prog', 'fake', 'fake2');
166 is( scalar @files, 0, '... should find no doc files given wrong dirs' );
167 @files = $ei->files('goodmod', 'prog');
168 is( scalar @files, 1, '... should find doc file in correct dir' );
169 like( $files[0], qr/foobar[>\]]?$/, '... checking file name' );
170 @files = $ei->files('goodmod');
171 is( scalar @files, 2 + $mandirs, '... should find all files with no type specified' );
172 my %dirnames = map { lc($_) => dirname($_) } @files;
175 my @dirs = $ei->directories('goodmod', 'prog', 'fake');
176 is( scalar @dirs, 0, 'directories() should return no dirs if no files found' );
179 skip('no man directories on this system', 1) unless $mandirs;
180 @dirs = $ei->directories('goodmod', 'doc');
181 is( scalar @dirs, $mandirs, '... should find all files files() would' );
183 @dirs = $ei->directories('goodmod');
184 is( scalar @dirs, 2 + $mandirs, '... should find all files files() would, again' );
185 @files = sort map { exists $dirnames{lc($_)} ? $dirnames{lc($_)} : '' } @files;
186 is( join(' ', @files), join(' ', @dirs), '... should sort output' );
191 (dirname($Config{man1direxp}) eq dirname($Config{man3direxp}))
195 skip('no man directories on this system', 1) unless $mandirs;
196 @dirs = $ei->directory_tree('goodmod', 'doc', $Config{man1direxp} ?
197 dirname($Config{man1direxp}) : dirname($Config{man3direxp}));
198 is( scalar @dirs, $expectdirs,
199 'directory_tree() should report intermediate dirs to those requested' );
202 my $fakepak = Fakepak->new(102);
206 packlist => $fakepak,
209 # these should all croak
210 foreach my $sub (qw( validate packlist version )) {
211 eval { $ei->$sub('nomod') };
212 like( $@, qr/nomod is not installed/,
213 "$sub() should croak when asked about uninstalled module" );
217 is( $ei->validate('yesmod'), 'validated',
218 'validate() should return results of packlist validate() call' );
221 is( ${ $ei->packlist('yesmod') }, 102,
222 'packlist() should report installed mod packlist' );
225 is( $ei->version('yesmod'), 101,
226 'version() should report installed mod version' );
230 for my $file (qw( .packlist FakePak.pm )) {
231 1 while unlink $file;
233 File::Path::rmtree('auto') or warn "Couldn't rmtree auto: $!";
241 bless(\(my $scalar = shift), $class);