Upgrade to ExtUtils-Manifest-1.49.
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / Installed.t
index 70287f8..c18e8b0 100644 (file)
@@ -5,24 +5,23 @@ BEGIN {
         chdir 't' if -d 't';
         @INC = '../lib';
     }
+    else {
+        unshift @INC, 't/lib/';
+    }
 }
 chdir 't';
 
+my $Is_VMS = $^O eq 'VMS';
 
 use strict;
-use warnings;
 
-# for _is_type() tests
 use Config;
-
-# for new() tests
 use Cwd;
 use File::Path;
-
-# for directories() tests
 use File::Basename;
+use File::Spec;
 
-use Test::More tests => 43;
+use Test::More tests => 46;
 
 BEGIN { use_ok( 'ExtUtils::Installed' ) }
 
@@ -32,119 +31,120 @@ my $mandirs =  !!$Config{man1direxp} + !!$Config{man3direxp};
 my $ei = bless( {}, 'ExtUtils::Installed' );
 
 # _is_prefix
-is( $ei->_is_prefix('foo/bar', 'foo'), 1, 
-       '_is_prefix() should match valid path prefix' );
-is( $ei->_is_prefix('\foo\bar', '\bar'), 0, 
-       '... should not match wrong prefix' );
+ok( $ei->_is_prefix('foo/bar', 'foo'),
+        '_is_prefix() should match valid path prefix' );
+ok( !$ei->_is_prefix('\foo\bar', '\bar'),
+        '... should not match wrong prefix' );
 
 # _is_type
-is( $ei->_is_type(0, 'all'), 1, '_is_type() should be true for type of "all"' );
+ok( $ei->_is_type(0, 'all'), '_is_type() should be true for type of "all"' );
 
 foreach my $path (qw( man1dir man3dir )) {
-SKIP: {
-       my $dir = $Config{$path.'exp'};
+    SKIP: {
+        my $dir = $Config{$path.'exp'};
         skip("no man directory $path on this system", 2 ) unless $dir;
 
-       my $file = $dir . '/foo';
-       is( $ei->_is_type($file, 'doc'), 1, "... should find doc file in $path" );
-       is( $ei->_is_type($file, 'prog'), 0, "... but not prog file in $path" );
+        my $file = $dir . '/foo';
+        ok( $ei->_is_type($file, 'doc'),   "... should find doc file in $path" );
+        ok( !$ei->_is_type($file, 'prog'), "... but not prog file in $path" );
     }
 }
 
-is( $ei->_is_type($Config{prefixexp} . '/bar', 'prog'), 1, 
-       "... should find prog file under $Config{prefixexp}" );
+# VMS 5.6.1 doesn't seem to have $Config{prefixexp}
+my $prefix = $Config{prefix} || $Config{prefixexp};
+
+# You can concatenate /foo but not foo:, which defaults in the current
+# directory
+$prefix = VMS::Filespec::unixify($prefix) if $Is_VMS;
+
+# ActivePerl 5.6.1/631 has $Config{prefixexp} as 'p:' for some reason
+$prefix = $Config{prefix} if $prefix eq 'p:' && $^O eq 'MSWin32';
+
+ok( $ei->_is_type( File::Spec->catfile($prefix, 'bar'), 'prog'),
+        "... should find prog file under $prefix" );
 
 SKIP: {
-       skip('no man directories on this system', 1) unless $mandirs;
-       is( $ei->_is_type('bar', 'doc'), 0, 
-               '... should not find doc file outside path' );
+    skip('no man directories on this system', 1) unless $mandirs;
+    is( $ei->_is_type('bar', 'doc'), 0,
+       '... should not find doc file outside path' );
 }
 
-is( $ei->_is_type('bar', 'prog'), 0, 
-       '... nor prog file outside path' );
-is( $ei->_is_type('whocares', 'someother'), 0, '... nor other type anywhere' );
+ok( !$ei->_is_type('bar', 'prog'),
+        '... nor prog file outside path' );
+ok( !$ei->_is_type('whocares', 'someother'), '... nor other type anywhere' );
 
 # _is_under
 ok( $ei->_is_under('foo'), '_is_under() should return true with no dirs' );
 
 my @under = qw( boo bar baz );
-is( $ei->_is_under('foo', @under), 0, '... should find no file not under dirs');
-is( $ei->_is_under('baz', @under), 1, '... should find file under dir' );
+ok( !$ei->_is_under('foo', @under), '... should find no file not under dirs');
+ok( $ei->_is_under('baz', @under),  '... should find file under dir' );
 
-# new
-my $realei;
-{
-    # We're going to get warnings about not being able to find install
-    # directories if we're not installed.
-    local $SIG{__WARN__} = sub {
-        warn @_ unless $ENV{PERL_CORE} && $_[0] =~ /^Can't stat/;
-    };
-    $realei = ExtUtils::Installed->new();
-}
 
-isa_ok( $realei, 'ExtUtils::Installed' );
-isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' );
-is( $realei->{Perl}{version}, $Config{version}, 
-       'new() should set Perl version from %Config' );
-
-my $wrotelist;
-if (mkpath('auto/FakeMod')) {
-       if (open(PACKLIST, '>', 'auto/FakeMod/.packlist')) {
-               print PACKLIST 'list';
-               close PACKLIST;
-               if (open(FAKEMOD, '>', 'auto/FakeMod/FakeMod.pm')) {
-                       print FAKEMOD <<'FAKE';
+rmtree 'auto/FakeMod';
+ok( mkpath('auto/FakeMod') );
+END { rmtree 'auto' }
+
+ok(open(PACKLIST, '>auto/FakeMod/.packlist'));
+print PACKLIST 'list';
+close PACKLIST;
+
+ok(open(FAKEMOD, '>auto/FakeMod/FakeMod.pm'));
+
+print FAKEMOD <<'FAKE';
 package FakeMod;
 use vars qw( $VERSION );
 $VERSION = '1.1.1';
 1;
 FAKE
 
-                       close FAKEMOD;
-                       $wrotelist = 1;
-               }
-       }
-}
+close FAKEMOD;
 
-
-SKIP: {
-       skip("could not write packlist: $!", 3 ) unless $wrotelist;
-
-       # avoid warning and death by localizing glob
-       local *ExtUtils::Installed::Config;
-       my $fake_mod_dir = File::Spec->catdir(cwd(), 'auto', 'FakeMod');
-       %ExtUtils::Installed::Config = (
-               archlibexp         => cwd(),
-               sitearchexp        => $fake_mod_dir,
-       );
-
-       # necessary to fool new()
-       push @INC, $fake_mod_dir;
-
-       my $realei = ExtUtils::Installed->new();
-       ok( exists $realei->{FakeMod}, 'new() should find modules with .packlists');
-       isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' );
-       is( $realei->{FakeMod}{version}, '1.1.1', 
-               '... should find version in modules' );
+{
+    # avoid warning and death by localizing glob
+    local *ExtUtils::Installed::Config;
+    my $fake_mod_dir = File::Spec->catdir(cwd(), 'auto', 'FakeMod');
+    %ExtUtils::Installed::Config = (
+        %Config,
+        archlibexp         => cwd(),
+        sitearchexp        => $fake_mod_dir,
+    );
+
+    # necessary to fool new()
+    push @INC, $fake_mod_dir;
+
+    my $realei = ExtUtils::Installed->new();
+    isa_ok( $realei, 'ExtUtils::Installed' );
+    isa_ok( $realei->{Perl}{packlist}, 'ExtUtils::Packlist' );
+    is( $realei->{Perl}{version}, $Config{version},
+        'new() should set Perl version from %Config' );
+
+    ok( exists $realei->{FakeMod}, 'new() should find modules with .packlists');
+    isa_ok( $realei->{FakeMod}{packlist}, 'ExtUtils::Packlist' );
+    is( $realei->{FakeMod}{version}, '1.1.1',
+       '... should find version in modules' );
 }
 
 # modules
 $ei->{$_} = 1 for qw( abc def ghi );
-is( join(' ', $ei->modules()), 'abc def ghi', 
-       'modules() should return sorted keys' );
+is( join(' ', $ei->modules()), 'abc def ghi',
+    'modules() should return sorted keys' );
+
+# This didn't work for a long time due to a sort in scalar context oddity.
+is( $ei->modules, 3,    'modules() in scalar context' );
 
 # files
-$ei->{goodmod} = { 
-       packlist => { 
-                ($Config{man1direxp} ? 
-                    (File::Spec->catdir($Config{man1direxp}, 'foo') => 1) : 
+$ei->{goodmod} = {
+        packlist => {
+                ($Config{man1direxp} ?
+                    (File::Spec->catdir($Config{man1direxp}, 'foo') => 1) :
                         ()),
-                ($Config{man3direxp} ? 
-                    (File::Spec->catdir($Config{man3direxp}, 'bar') => 1) : 
+                ($Config{man3direxp} ?
+                    (File::Spec->catdir($Config{man3direxp}, 'bar') => 1) :
                         ()),
-                File::Spec->catdir($Config{prefixexp}, 'foobar') => 1,
-               foobaz  => 1,
-       },
+                File::Spec->catdir($prefix, 'foobar') => 1,
+                foobaz  => 1,
+        },
 };
 
 eval { $ei->files('badmod') };
@@ -154,10 +154,11 @@ like( $@, qr/type must be/,'files() should croak given bad type' );
 
 my @files;
 SKIP: {
-    skip('no man directory man1dir on this system', 2) unless $Config{man1direxp}; 
+    skip('no man directory man1dir on this system', 2)
+      unless $Config{man1direxp};
     @files = $ei->files('goodmod', 'doc', $Config{man1direxp});
     is( scalar @files, 1, '... should find doc file under given dir' );
-    is( grep({ /foo$/ } @files), 1, '... checking file name' );
+    is( (grep { /foo$/ } @files), 1, '... checking file name' );
 }
 SKIP: {
     skip('no man directories on this system', 1) unless $mandirs;
@@ -169,7 +170,7 @@ SKIP: {
 is( scalar @files, 0, '... should find no doc files given wrong dirs' );
 @files = $ei->files('goodmod', 'prog');
 is( scalar @files, 1, '... should find doc file in correct dir' );
-like( $files[0], qr/foobar$/, '... checking file name' );
+like( $files[0], qr/foobar[>\]]?$/, '... checking file name' );
 @files = $ei->files('goodmod');
 is( scalar @files, 2 + $mandirs, '... should find all files with no type specified' );
 my %dirnames = map { lc($_) => dirname($_) } @files;
@@ -189,64 +190,53 @@ is( scalar @dirs, 2 + $mandirs, '... should find all files files() would, again'
 is( join(' ', @files), join(' ', @dirs), '... should sort output' );
 
 # directory_tree
-my $expectdirs = 
-       ($mandirs == 2) && 
+my $expectdirs =
+       ($mandirs == 2) &&
        (dirname($Config{man1direxp}) eq dirname($Config{man3direxp}))
        ? 3 : 2;
+
 SKIP: {
     skip('no man directories on this system', 1) unless $mandirs;
     @dirs = $ei->directory_tree('goodmod', 'doc', $Config{man1direxp} ?
        dirname($Config{man1direxp}) : dirname($Config{man3direxp}));
-    is( scalar @dirs, $expectdirs, 
+    is( scalar @dirs, $expectdirs,
         'directory_tree() should report intermediate dirs to those requested' );
 }
 
 my $fakepak = Fakepak->new(102);
 
-$ei->{yesmod} = { 
-       version         => 101,
-       packlist        => $fakepak,
+$ei->{yesmod} = {
+        version         => 101,
+        packlist        => $fakepak,
 };
 
 # these should all croak
 foreach my $sub (qw( validate packlist version )) {
-       eval { $ei->$sub('nomod') };
-       like( $@, qr/nomod is not installed/, 
-               "$sub() should croak when asked about uninstalled module" );
+    eval { $ei->$sub('nomod') };
+    like( $@, qr/nomod is not installed/,
+         "$sub() should croak when asked about uninstalled module" );
 }
 
 # validate
-is( $ei->validate('yesmod'), 'validated', 
-       'validate() should return results of packlist validate() call' );
+is( $ei->validate('yesmod'), 'validated',
+        'validate() should return results of packlist validate() call' );
 
 # packlist
-is( ${ $ei->packlist('yesmod') }, 102, 
-       'packlist() should report installed mod packlist' );
+is( ${ $ei->packlist('yesmod') }, 102,
+        'packlist() should report installed mod packlist' );
 
 # version
-is( $ei->version('yesmod'), 101, 
-       'version() should report installed mod version' );
-
-# needs a DESTROY, for some reason
-can_ok( $ei, 'DESTROY' );
-
-END {
-       if ($wrotelist) {
-               for my $file (qw( .packlist FakePak.pm )) {
-                       1 while unlink $file;
-               }
-               File::Path::rmtree('auto') or warn "Couldn't rmtree auto: $!";
-       }
-}
+is( $ei->version('yesmod'), 101,
+        'version() should report installed mod version' );
+
 
 package Fakepak;
 
 sub new {
-       my $class = shift;
-       bless(\(my $scalar = shift), $class);
+    my $class = shift;
+    bless(\(my $scalar = shift), $class);
 }
 
 sub validate {
-       'validated'
+    return 'validated'
 }