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