ExtUtils::MakeMaker 6.03 -> 6.06_05ish
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / Manifest.t
index f531406..4d76b94 100644 (file)
@@ -1,32 +1,46 @@
-#!./perl 
+#!/usr/bin/perl -w
 
 BEGIN {
-    chdir 't' if -d 't';
-    unshift @INC, '../lib';
+    if( $ENV{PERL_CORE} ) {
+        chdir 't' if -d 't';
+        unshift @INC, '../lib';
+    }
+    else {
+        unshift @INC, 't/lib';
+    }
 }
+chdir 't';
+
+use strict;
 
 # these files help the test run
-use Test::More tests => 31;
+use Test::More tests => 37;
 use Cwd;
 
 # these files are needed for the module itself
 use File::Spec;
 use File::Path;
-use Carp::Heavy;
+
+# We're going to be chdir'ing and modules are sometimes loaded on the
+# fly in this test, so we need an absolute @INC.
+@INC = map { File::Spec->rel2abs($_) } @INC;
 
 # keep track of everything added so it can all be deleted
-my @files;
+my %files;
 sub add_file {
-       my ($file, $data) = @_;
-       $data ||= 'foo';
-       open( my $T, '>', $file) or return;
-       print $T $data;
-       push @files, $file;
+    my ($file, $data) = @_;
+    $data ||= 'foo';
+    unlink $file;  # or else we'll get multiple versions on VMS
+    open( T, '>'.$file) or return;
+    print T $data;
+    ++$files{$file};
+    close T;
 }
 
 sub read_manifest {
-       open( my $M, 'MANIFEST' ) or return;
-       chomp( my @files = <$M> );
+       open( M, 'MANIFEST' ) or return;
+       chomp( my @files = <M> );
+    close M;
        return @files;
 }
 
@@ -41,8 +55,11 @@ sub remove_dir {
 }
 
 # use module, import functions
-use_ok( 'ExtUtils::Manifest', 
-       qw( mkmanifest manicheck filecheck fullcheck maniread manicopy) );
+BEGIN { 
+    use_ok( 'ExtUtils::Manifest', 
+            qw( mkmanifest manicheck filecheck fullcheck 
+                maniread manicopy skipcheck maniadd) ); 
+}
 
 my $cwd = Cwd::getcwd();
 
@@ -56,9 +73,10 @@ ok( add_file('foo'), 'add a temporary file' );
 # there shouldn't be a MANIFEST there
 my ($res, $warn) = catch_warning( \&mkmanifest ); 
 # Canonize the order.
-$warn = join("", map { "$_|" } sort { lc $a cmp lc $b } split /\r?\n/, $warn);
+$warn = join("", map { "$_|" } 
+                 sort { lc($a) cmp lc($b) } split /\r?\n/, $warn);
 is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
-    "mkmanifest() displayed it's additions" );
+    "mkmanifest() displayed its additions" );
 
 # and now you see it
 ok( -e 'MANIFEST', 'create MANIFEST file' );
@@ -78,75 +96,102 @@ like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
 is( $res, 'bar', 'bar reported as new' );
 
 # now quiet the warning that bar was added and test again
-use vars qw($ExtUtils::Manifest::Quiet);
-$ExtUtils::Manifest::Quiet = 1;
-($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
-is( $warn, '', 'disabled warnings' );
+($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1; 
+                     catch_warning( \&skipcheck ) 
+                };
+cmp_ok( $warn, 'eq', '', 'disabled warnings' );
 
-# add a skip file with a rule to skip itself
+# add a skip file with a rule to skip itself (and the nonexistent glob '*baz*')
 add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
 
 # this'll skip the new file
-($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
-like( $warn, qr/^Skipping MANIFEST\.SKIP/, 'got skipping warning' );
+($res, $warn) = catch_warning( \&skipcheck );
+like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' );
 
-# I'm not sure why this should be... shouldn't $missing be the only one?
-my ($found, $missing );
+my @skipped;
 catch_warning( sub {
-       ( $found, $missing ) = ExtUtils::Manifest::skipcheck()
+       @skipped = skipcheck()
 });
 
-# nothing new should be found, bar should be skipped
-is( @$found, 0, 'no output here' );
-is( join( ' ', @$missing ), 'bar', 'listed skipped files' );
+is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' );
 
-is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
+{
+       local $ExtUtils::Manifest::Quiet = 1;
+       is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
+}
 
 # add a subdirectory and a file there that should be found
 ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
-my $quux = File::Spec->catfile( 'moretest', 'quux' );
-$quux =~ s#\\#/#g;
-$quux = VMS::Filespec::unixify($quux) if $^O eq 'VMS';
-add_file( $quux, 'quux' );
-ok( exists( ExtUtils::Manifest::manifind()->{$quux} ), "manifind found $quux" );
+add_file( File::Spec->catfile('moretest', 'quux'), 'quux' );
+ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ), 
+                                        "manifind found moretest/quux" );
 
 # only MANIFEST and foo are in the manifest
 my $files = maniread();
 is( keys %$files, 2, 'two files found' );
-is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST', 'both files found' );
+is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST', 
+                                        'both files found' );
 
 # poison the manifest, and add a comment that should be reported
 add_file( 'MANIFEST', 'none #none' );
-is( ExtUtils::Manifest::maniread()->{none}, '#none', 'maniread found comment' );
+is( ExtUtils::Manifest::maniread()->{none}, '#none', 
+                                        'maniread found comment' );
 
 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
 
 $files = maniread();
 eval { (undef, $warn) = catch_warning( sub {
-               manicopy( $files, 'copy', 'cp' ) }) 
+               manicopy( $files, 'copy', 'cp' ) }) 
 };
+like( $@, qr/^Can't read none: /, 'croaked about none' );
 
 # a newline comes through, so get rid of it
 chomp($warn);
 
 # the copy should have given one warning and one error
-is($warn, 'Skipping MANIFEST.SKIP', 'warned about MANIFEST.SKIP' );
-like( $@, qr/^Can't read none: /, 
-                                               'carped about none' );
+like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' );
 
 # tell ExtUtils::Manifest to use a different file
-use vars qw($ExtUtils::Manifest::MANIFEST);
-$ExtUtils::Manifest::MANIFEST = 'albatross';
+{
+       local $ExtUtils::Manifest::MANIFEST = 'albatross'; 
+       ($res, $warn) = catch_warning( \&mkmanifest );
+       like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
+       
+       # add the new file to the list of files to be deleted
+       $files{'albatross'}++;
+}
+
+
+# Make sure MANIFEST.SKIP is using complete relative paths
+add_file( 'MANIFEST.SKIP' => "^moretest/q\n" );
+
+# This'll skip moretest/quux
+($res, $warn) = catch_warning( \&skipcheck );
+like( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' );
+
+
+# There was a bug where entries in MANIFEST would be blotted out
+# by MANIFEST.SKIP rules.
+add_file( 'MANIFEST.SKIP' => 'foo' );
+add_file( 'MANIFEST'      => "foobar\n"   );
+add_file( 'foobar'        => '123' );
+($res, $warn) = catch_warning( \&manicheck );
+is( $res,  '',      'MANIFEST overrides MANIFEST.SKIP' );
+is( $warn, undef,   'MANIFEST overrides MANIFEST.SKIP, no warnings' );
 
-($res, $warn) = catch_warning( \&mkmanifest );
-like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
+$files = maniread;
+ok( !$files->{wibble},     'MANIFEST in good state' );
+maniadd({ wibble => undef });
+maniadd({ yarrow => "hock" });
+$files = maniread;
+is( $files->{wibble}, '',    'maniadd() with undef comment' );
+is( $files->{yarrow}, 'hock','          with comment' );
+is( $files->{foobar}, '',    '          preserved old entries' );
 
-# add the new file to the list of files to be deleted
-push @files, 'albatross';
 
 END {
-       # the arrays are evaluated in scalar context
-       is( unlink( @files ), @files, 'remove all added files' );
+       # the args are evaluated in scalar context
+       is( unlink( keys %files ), keys %files, 'remove all added files' );
        remove_dir( 'moretest', 'copy' );
 
        # now get rid of the parent directory