1N/A#!/usr/bin/perl -w
1N/A
1N/ABEGIN {
1N/A if( $ENV{PERL_CORE} ) {
1N/A chdir 't' if -d 't';
1N/A unshift @INC, '../lib';
1N/A }
1N/A else {
1N/A unshift @INC, 't/lib';
1N/A }
1N/A}
1N/Achdir 't';
1N/A
1N/Ause strict;
1N/A
1N/A# these files help the test run
1N/Ause Test::More tests => 41;
1N/Ause Cwd;
1N/A
1N/A# these files are needed for the module itself
1N/Ause File::Spec;
1N/Ause File::Path;
1N/A
1N/A# We're going to be chdir'ing and modules are sometimes loaded on the
1N/A# fly in this test, so we need an absolute @INC.
1N/A@INC = map { File::Spec->rel2abs($_) } @INC;
1N/A
1N/A# keep track of everything added so it can all be deleted
1N/Amy %Files;
1N/Asub add_file {
1N/A my ($file, $data) = @_;
1N/A $data ||= 'foo';
1N/A 1 while unlink $file; # or else we'll get multiple versions on VMS
1N/A open( T, '>'.$file) or return;
1N/A print T $data;
1N/A ++$Files{$file};
1N/A close T;
1N/A}
1N/A
1N/Asub read_manifest {
1N/A open( M, 'MANIFEST' ) or return;
1N/A chomp( my @files = <M> );
1N/A close M;
1N/A return @files;
1N/A}
1N/A
1N/Asub catch_warning {
1N/A my $warn;
1N/A local $SIG{__WARN__} = sub { $warn .= $_[0] };
1N/A return join('', $_[0]->() ), $warn;
1N/A}
1N/A
1N/Asub remove_dir {
1N/A ok( rmdir( $_ ), "remove $_ directory" ) for @_;
1N/A}
1N/A
1N/A# use module, import functions
1N/ABEGIN {
1N/A use_ok( 'ExtUtils::Manifest',
1N/A qw( mkmanifest manicheck filecheck fullcheck
1N/A maniread manicopy skipcheck maniadd) );
1N/A}
1N/A
1N/Amy $cwd = Cwd::getcwd();
1N/A
1N/A# Just in case any old files were lying around.
1N/Armtree('mantest');
1N/A
1N/Aok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
1N/Aok( chdir( 'mantest' ), 'chdir() to mantest' );
1N/Aok( add_file('foo'), 'add a temporary file' );
1N/A
1N/A# there shouldn't be a MANIFEST there
1N/Amy ($res, $warn) = catch_warning( \&mkmanifest );
1N/A# Canonize the order.
1N/A$warn = join("", map { "$_|" }
1N/A sort { lc($a) cmp lc($b) } split /\r?\n/, $warn);
1N/Ais( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
1N/A "mkmanifest() displayed its additions" );
1N/A
1N/A# and now you see it
1N/Aok( -e 'MANIFEST', 'create MANIFEST file' );
1N/A
1N/Amy @list = read_manifest();
1N/Ais( @list, 2, 'check files in MANIFEST' );
1N/Aok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
1N/A
1N/A# after adding bar, the MANIFEST is out of date
1N/Aok( add_file( 'bar' ), 'add another file' );
1N/Aok( ! manicheck(), 'MANIFEST now out of sync' );
1N/A
1N/A# it reports that bar has been added and throws a warning
1N/A($res, $warn) = catch_warning( \&filecheck );
1N/A
1N/Alike( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
1N/Ais( $res, 'bar', 'bar reported as new' );
1N/A
1N/A# now quiet the warning that bar was added and test again
1N/A($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1;
1N/A catch_warning( \&skipcheck )
1N/A };
1N/Acmp_ok( $warn, 'eq', '', 'disabled warnings' );
1N/A
1N/A# add a skip file with a rule to skip itself (and the nonexistent glob '*baz*')
1N/Aadd_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
1N/A
1N/A# this'll skip the new file
1N/A($res, $warn) = catch_warning( \&skipcheck );
1N/Alike( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' );
1N/A
1N/Amy @skipped;
1N/Acatch_warning( sub {
1N/A @skipped = skipcheck()
1N/A});
1N/A
1N/Ais( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' );
1N/A
1N/A{
1N/A local $ExtUtils::Manifest::Quiet = 1;
1N/A is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
1N/A}
1N/A
1N/A# add a subdirectory and a file there that should be found
1N/Aok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
1N/Aadd_file( File::Spec->catfile('moretest', 'quux'), 'quux' );
1N/Aok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ),
1N/A "manifind found moretest/quux" );
1N/A
1N/A# only MANIFEST and foo are in the manifest
1N/A$_ = 'foo';
1N/Amy $files = maniread();
1N/Ais( keys %$files, 2, 'two files found' );
1N/Ais( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST',
1N/A 'both files found' );
1N/Ais( $_, 'foo', q{maniread() doesn't clobber $_} );
1N/A
1N/A# poison the manifest, and add a comment that should be reported
1N/Aadd_file( 'MANIFEST', 'none #none' );
1N/Ais( ExtUtils::Manifest::maniread()->{none}, '#none',
1N/A 'maniread found comment' );
1N/A
1N/Aok( mkdir( 'copy', 0777 ), 'made copy directory' );
1N/A
1N/A$files = maniread();
1N/Aeval { (undef, $warn) = catch_warning( sub {
1N/A manicopy( $files, 'copy', 'cp' ) })
1N/A};
1N/Alike( $@, qr/^Can't read none: /, 'croaked about none' );
1N/A
1N/A# a newline comes through, so get rid of it
1N/Achomp($warn);
1N/A
1N/A# the copy should have given one warning and one error
1N/Alike($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' );
1N/A
1N/A# tell ExtUtils::Manifest to use a different file
1N/A{
1N/A local $ExtUtils::Manifest::MANIFEST = 'albatross';
1N/A ($res, $warn) = catch_warning( \&mkmanifest );
1N/A like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
1N/A
1N/A # add the new file to the list of files to be deleted
1N/A $Files{'albatross'}++;
1N/A}
1N/A
1N/A
1N/A# Make sure MANIFEST.SKIP is using complete relative paths
1N/Aadd_file( 'MANIFEST.SKIP' => "^moretest/q\n" );
1N/A
1N/A# This'll skip moretest/quux
1N/A($res, $warn) = catch_warning( \&skipcheck );
1N/Alike( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' );
1N/A
1N/A
1N/A# There was a bug where entries in MANIFEST would be blotted out
1N/A# by MANIFEST.SKIP rules.
1N/Aadd_file( 'MANIFEST.SKIP' => 'foo' );
1N/Aadd_file( 'MANIFEST' => "foobar\n" );
1N/Aadd_file( 'foobar' => '123' );
1N/A($res, $warn) = catch_warning( \&manicheck );
1N/Ais( $res, '', 'MANIFEST overrides MANIFEST.SKIP' );
1N/Ais( $warn, undef, 'MANIFEST overrides MANIFEST.SKIP, no warnings' );
1N/A
1N/A$files = maniread;
1N/Aok( !$files->{wibble}, 'MANIFEST in good state' );
1N/Amaniadd({ wibble => undef });
1N/Amaniadd({ yarrow => "hock" });
1N/A$files = maniread;
1N/Ais( $files->{wibble}, '', 'maniadd() with undef comment' );
1N/Ais( $files->{yarrow}, 'hock',' with comment' );
1N/Ais( $files->{foobar}, '', ' preserved old entries' );
1N/A
1N/Aadd_file('MANIFEST' => 'Makefile.PL');
1N/Amaniadd({ foo => 'bar' });
1N/A$files = maniread;
1N/A# VMS downcases the MANIFEST. We normalize it here to match.
1N/A%$files = map { (lc $_ => $files->{$_}) } keys %$files;
1N/Amy %expect = ( 'makefile.pl' => '',
1N/A 'foo' => 'bar'
1N/A );
1N/Ais_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline');
1N/A
1N/Aadd_file('MANIFEST' => 'Makefile.PL');
1N/Amaniadd({ foo => 'bar' });
1N/A
1N/ASKIP: {
1N/A chmod( 0400, 'MANIFEST' );
1N/A skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST';
1N/A
1N/A eval {
1N/A maniadd({ 'foo' => 'bar' });
1N/A };
1N/A is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" );
1N/A
1N/A eval {
1N/A maniadd({ 'grrrwoof' => 'yippie' });
1N/A };
1N/A like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/,
1N/A "maniadd() dies if it can't open the MANIFEST" );
1N/A
1N/A chmod( 0600, 'MANIFEST' );
1N/A}
1N/A
1N/A
1N/AEND {
1N/A is( unlink( keys %Files ), keys %Files, 'remove all added files' );
1N/A remove_dir( 'moretest', 'copy' );
1N/A
1N/A # now get rid of the parent directory
1N/A ok( chdir( $cwd ), 'return to parent directory' );
1N/A remove_dir( 'mantest' );
1N/A}
1N/A