Commit | Line | Data |
39234879 |
1 | #!/usr/bin/perl -w |
2 | |
3 | BEGIN { |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't' if -d 't'; |
6 | @INC = '../lib'; |
7 | } |
f6d6199c |
8 | else { |
9 | unshift @INC, 't/lib/'; |
10 | } |
39234879 |
11 | } |
7292dc67 |
12 | chdir 't'; |
431b0fc4 |
13 | |
14 | my $Is_VMS = $^O eq 'VMS'; |
f411ddcc |
15 | |
16 | use strict; |
f411ddcc |
17 | |
f411ddcc |
18 | use Config; |
f411ddcc |
19 | use Cwd; |
20 | use File::Path; |
f411ddcc |
21 | use File::Basename; |
f6d6199c |
22 | use File::Spec; |
f411ddcc |
23 | |
d5d4ec93 |
24 | use Test::More tests => 46; |
f411ddcc |
25 | |
39234879 |
26 | BEGIN { use_ok( 'ExtUtils::Installed' ) } |
f411ddcc |
27 | |
34dcf69d |
28 | my $mandirs = !!$Config{man1direxp} + !!$Config{man3direxp}; |
64f50df3 |
29 | |
f411ddcc |
30 | # saves having to qualify package name for class methods |
31 | my $ei = bless( {}, 'ExtUtils::Installed' ); |
32 | |
33 | # _is_prefix |
f6d6199c |
34 | ok( $ei->_is_prefix('foo/bar', 'foo'), |
41e5fcb0 |
35 | '_is_prefix() should match valid path prefix' ); |
f6d6199c |
36 | ok( !$ei->_is_prefix('\foo\bar', '\bar'), |
41e5fcb0 |
37 | '... should not match wrong prefix' ); |
f411ddcc |
38 | |
39 | # _is_type |
f6d6199c |
40 | ok( $ei->_is_type(0, 'all'), '_is_type() should be true for type of "all"' ); |
f411ddcc |
41 | |
34dcf69d |
42 | foreach my $path (qw( man1dir man3dir )) { |
41e5fcb0 |
43 | SKIP: { |
44 | my $dir = $Config{$path.'exp'}; |
34dcf69d |
45 | skip("no man directory $path on this system", 2 ) unless $dir; |
46 | |
41e5fcb0 |
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" ); |
34dcf69d |
50 | } |
f411ddcc |
51 | } |
52 | |
f6d6199c |
53 | # VMS 5.6.1 doesn't seem to have $Config{prefixexp} |
54 | my $prefix = $Config{prefix} || $Config{prefixexp}; |
55 | |
3a465856 |
56 | # You can concatenate /foo but not foo:, which defaults in the current |
f6d6199c |
57 | # directory |
431b0fc4 |
58 | $prefix = VMS::Filespec::unixify($prefix) if $Is_VMS; |
f6d6199c |
59 | |
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'; |
62 | |
63 | ok( $ei->_is_type( File::Spec->catfile($prefix, 'bar'), 'prog'), |
41e5fcb0 |
64 | "... should find prog file under $prefix" ); |
64f50df3 |
65 | |
66 | SKIP: { |
41e5fcb0 |
67 | skip('no man directories on this system', 1) unless $mandirs; |
3a465856 |
68 | is( $ei->_is_type('bar', 'doc'), 0, |
41e5fcb0 |
69 | '... should not find doc file outside path' ); |
64f50df3 |
70 | } |
71 | |
f6d6199c |
72 | ok( !$ei->_is_type('bar', 'prog'), |
41e5fcb0 |
73 | '... nor prog file outside path' ); |
f6d6199c |
74 | ok( !$ei->_is_type('whocares', 'someother'), '... nor other type anywhere' ); |
f411ddcc |
75 | |
76 | # _is_under |
77 | ok( $ei->_is_under('foo'), '_is_under() should return true with no dirs' ); |
78 | |
79 | my @under = qw( boo bar baz ); |
f6d6199c |
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' ); |
f411ddcc |
82 | |
f411ddcc |
83 | |
d5d4ec93 |
84 | rmtree 'auto/FakeMod'; |
85 | ok( mkpath('auto/FakeMod') ); |
b5f5ff40 |
86 | END { rmtree 'auto' } |
57b1a898 |
87 | |
88 | ok(open(PACKLIST, '>auto/FakeMod/.packlist')); |
89 | print PACKLIST 'list'; |
90 | close PACKLIST; |
91 | |
92 | ok(open(FAKEMOD, '>auto/FakeMod/FakeMod.pm')); |
93 | |
94 | print FAKEMOD <<'FAKE'; |
f411ddcc |
95 | package FakeMod; |
96 | use vars qw( $VERSION ); |
97 | $VERSION = '1.1.1'; |
98 | 1; |
99 | FAKE |
100 | |
57b1a898 |
101 | close FAKEMOD; |
f411ddcc |
102 | |
57b1a898 |
103 | { |
104 | # avoid warning and death by localizing glob |
105 | local *ExtUtils::Installed::Config; |
106 | my $fake_mod_dir = File::Spec->catdir(cwd(), 'auto', 'FakeMod'); |
107 | %ExtUtils::Installed::Config = ( |
108 | %Config, |
41e5fcb0 |
109 | archlibexp => cwd(), |
110 | sitearchexp => $fake_mod_dir, |
57b1a898 |
111 | ); |
f411ddcc |
112 | |
41e5fcb0 |
113 | # necessary to fool new() |
114 | push @INC, $fake_mod_dir; |
f411ddcc |
115 | |
41e5fcb0 |
116 | my $realei = ExtUtils::Installed->new(); |
57b1a898 |
117 | isa_ok( $realei, 'ExtUtils::Installed' ); |
118 | isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' ); |
3a465856 |
119 | is( $realei->{Perl}{version}, $Config{version}, |
57b1a898 |
120 | 'new() should set Perl version from %Config' ); |
121 | |
41e5fcb0 |
122 | ok( exists $realei->{FakeMod}, 'new() should find modules with .packlists'); |
123 | isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' ); |
3a465856 |
124 | is( $realei->{FakeMod}{version}, '1.1.1', |
41e5fcb0 |
125 | '... should find version in modules' ); |
f411ddcc |
126 | } |
127 | |
128 | # modules |
129 | $ei->{$_} = 1 for qw( abc def ghi ); |
3a465856 |
130 | is( join(' ', $ei->modules()), 'abc def ghi', |
41e5fcb0 |
131 | 'modules() should return sorted keys' ); |
f411ddcc |
132 | |
d5d4ec93 |
133 | # This didn't work for a long time due to a sort in scalar context oddity. |
134 | is( $ei->modules, 3, 'modules() in scalar context' ); |
135 | |
f411ddcc |
136 | # files |
3a465856 |
137 | $ei->{goodmod} = { |
138 | packlist => { |
139 | ($Config{man1direxp} ? |
140 | (File::Spec->catdir($Config{man1direxp}, 'foo') => 1) : |
34dcf69d |
141 | ()), |
3a465856 |
142 | ($Config{man3direxp} ? |
143 | (File::Spec->catdir($Config{man3direxp}, 'bar') => 1) : |
34dcf69d |
144 | ()), |
f6d6199c |
145 | File::Spec->catdir($prefix, 'foobar') => 1, |
41e5fcb0 |
146 | foobaz => 1, |
147 | }, |
f411ddcc |
148 | }; |
149 | |
150 | eval { $ei->files('badmod') }; |
151 | like( $@, qr/badmod is not installed/,'files() should croak given bad modname'); |
152 | eval { $ei->files('goodmod', 'badtype' ) }; |
153 | like( $@, qr/type must be/,'files() should croak given bad type' ); |
64f50df3 |
154 | |
155 | my @files; |
156 | SKIP: { |
3a465856 |
157 | skip('no man directory man1dir on this system', 2) |
158 | unless $Config{man1direxp}; |
34dcf69d |
159 | @files = $ei->files('goodmod', 'doc', $Config{man1direxp}); |
160 | is( scalar @files, 1, '... should find doc file under given dir' ); |
57b1a898 |
161 | is( (grep { /foo$/ } @files), 1, '... checking file name' ); |
34dcf69d |
162 | } |
163 | SKIP: { |
164 | skip('no man directories on this system', 1) unless $mandirs; |
165 | @files = $ei->files('goodmod', 'doc'); |
166 | is( scalar @files, $mandirs, '... should find all doc files with no dir' ); |
64f50df3 |
167 | } |
168 | |
f411ddcc |
169 | @files = $ei->files('goodmod', 'prog', 'fake', 'fake2'); |
170 | is( scalar @files, 0, '... should find no doc files given wrong dirs' ); |
171 | @files = $ei->files('goodmod', 'prog'); |
172 | is( scalar @files, 1, '... should find doc file in correct dir' ); |
b4558e59 |
173 | like( $files[0], qr/foobar[>\]]?$/, '... checking file name' ); |
f411ddcc |
174 | @files = $ei->files('goodmod'); |
34dcf69d |
175 | is( scalar @files, 2 + $mandirs, '... should find all files with no type specified' ); |
62bfa7e0 |
176 | my %dirnames = map { lc($_) => dirname($_) } @files; |
f411ddcc |
177 | |
178 | # directories |
179 | my @dirs = $ei->directories('goodmod', 'prog', 'fake'); |
180 | is( scalar @dirs, 0, 'directories() should return no dirs if no files found' ); |
64f50df3 |
181 | |
182 | SKIP: { |
34dcf69d |
183 | skip('no man directories on this system', 1) unless $mandirs; |
184 | @dirs = $ei->directories('goodmod', 'doc'); |
185 | is( scalar @dirs, $mandirs, '... should find all files files() would' ); |
186 | } |
187 | @dirs = $ei->directories('goodmod'); |
188 | is( scalar @dirs, 2 + $mandirs, '... should find all files files() would, again' ); |
189 | @files = sort map { exists $dirnames{lc($_)} ? $dirnames{lc($_)} : '' } @files; |
190 | is( join(' ', @files), join(' ', @dirs), '... should sort output' ); |
191 | |
192 | # directory_tree |
3a465856 |
193 | my $expectdirs = |
194 | ($mandirs == 2) && |
34dcf69d |
195 | (dirname($Config{man1direxp}) eq dirname($Config{man3direxp})) |
196 | ? 3 : 2; |
3a465856 |
197 | |
34dcf69d |
198 | SKIP: { |
199 | skip('no man directories on this system', 1) unless $mandirs; |
200 | @dirs = $ei->directory_tree('goodmod', 'doc', $Config{man1direxp} ? |
201 | dirname($Config{man1direxp}) : dirname($Config{man3direxp})); |
3a465856 |
202 | is( scalar @dirs, $expectdirs, |
34dcf69d |
203 | 'directory_tree() should report intermediate dirs to those requested' ); |
64f50df3 |
204 | } |
f411ddcc |
205 | |
206 | my $fakepak = Fakepak->new(102); |
207 | |
3a465856 |
208 | $ei->{yesmod} = { |
41e5fcb0 |
209 | version => 101, |
210 | packlist => $fakepak, |
f411ddcc |
211 | }; |
212 | |
213 | # these should all croak |
214 | foreach my $sub (qw( validate packlist version )) { |
41e5fcb0 |
215 | eval { $ei->$sub('nomod') }; |
3a465856 |
216 | like( $@, qr/nomod is not installed/, |
41e5fcb0 |
217 | "$sub() should croak when asked about uninstalled module" ); |
f411ddcc |
218 | } |
219 | |
220 | # validate |
3a465856 |
221 | is( $ei->validate('yesmod'), 'validated', |
41e5fcb0 |
222 | 'validate() should return results of packlist validate() call' ); |
f411ddcc |
223 | |
224 | # packlist |
3a465856 |
225 | is( ${ $ei->packlist('yesmod') }, 102, |
41e5fcb0 |
226 | 'packlist() should report installed mod packlist' ); |
f411ddcc |
227 | |
228 | # version |
3a465856 |
229 | is( $ei->version('yesmod'), 101, |
41e5fcb0 |
230 | 'version() should report installed mod version' ); |
f411ddcc |
231 | |
f411ddcc |
232 | |
233 | package Fakepak; |
234 | |
235 | sub new { |
41e5fcb0 |
236 | my $class = shift; |
237 | bless(\(my $scalar = shift), $class); |
f411ddcc |
238 | } |
239 | |
240 | sub validate { |
41e5fcb0 |
241 | return 'validated' |
f411ddcc |
242 | } |