From: Michael G. Schwern Date: Fri, 7 Sep 2001 23:06:51 +0000 (-0400) Subject: [REPATCH] Re: [PATCH MANIFEST, lib/ExtUtils/Manifest.t] Another New Test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0300da759abdff9574616487473c72790a5d8244;p=p5sagit%2Fp5-mst-13.2.git [REPATCH] Re: [PATCH MANIFEST, lib/ExtUtils/Manifest.t] Another New Test Message-ID: <20010907230651.R606@blackrider> p4raw-id: //depot/perl@11946 --- diff --git a/MANIFEST b/MANIFEST index 8232d04..6a3420c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -857,6 +857,7 @@ lib/ExtUtils/Installed.pm Information on installed extensions lib/ExtUtils/Liblist.pm Locates libraries lib/ExtUtils/MakeMaker.pm Write Makefiles for extensions lib/ExtUtils/Manifest.pm Utilities to write MANIFEST files +lib/ExtUtils/Manifest.t See if ExtUtils::Manifest works lib/ExtUtils/MANIFEST.SKIP The default MANIFEST.SKIP lib/ExtUtils/Mkbootstrap.pm Writes a bootstrap file (see MakeMaker) lib/ExtUtils/Mksymlists.pm Writes a linker options file for extensions diff --git a/lib/ExtUtils/Manifest.pm b/lib/ExtUtils/Manifest.pm index 7b3dbff..e626fa1 100644 --- a/lib/ExtUtils/Manifest.pm +++ b/lib/ExtUtils/Manifest.pm @@ -35,7 +35,7 @@ unless (defined $Config{d_link}) { sub mkmanifest { my $manimiss = 0; - my $read = maniread() or $manimiss++; + my $read = (-r 'MANIFEST' && maniread()) or $manimiss++; $read = {} if $manimiss; local *M; rename $MANIFEST, "$MANIFEST.bak" unless $manimiss; diff --git a/lib/ExtUtils/Manifest.t b/lib/ExtUtils/Manifest.t new file mode 100644 index 0000000..a1452b9 --- /dev/null +++ b/lib/ExtUtils/Manifest.t @@ -0,0 +1,153 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + unshift @INC, '../lib'; +} + +# these files help the test run +use Test::More tests => 31; +use Cwd; + +# these files are needed for the module itself +use File::Spec; +use File::Path; +use Carp::Heavy; + +# keep track of everything added so it can all be deleted +my @files; +sub add_file { + my ($file, $data) = @_; + $data ||= 'foo'; + open( my $T, ">$file") or return; + print $T $data; + push @files, $file; +} + +sub read_manifest { + open( my $M, 'MANIFEST' ) or return; + chomp( my @files = <$M> ); + return @files; +} + +sub catch_warning { + my $warn; + local $SIG{__WARN__} = sub { $warn .= $_[0] }; + return join('', $_[0]->() ), $warn; +} + +sub remove_dir { + ok( rmdir( $_ ), "remove $_ directory" ) for @_; +} + +# use module, import functions +use_ok( 'ExtUtils::Manifest', + qw( mkmanifest manicheck filecheck fullcheck maniread manicopy) ); + +my $cwd = Cwd::getcwd(); + +# Just in case any old files were lying around. +rmtree('mantest'); + +ok( mkdir( 'mantest', 0777 ), 'make mantest directory' ); +ok( chdir( 'mantest' ), 'chdir() to mantest' ); +ok( add_file('foo'), 'add a temporary file' ); + +# there shouldn't be a MANIFEST there +my ($res, $warn) = catch_warning( \&mkmanifest ); +is( $warn, <catfile( 'moretest', 'quux' ); +add_file( $quux, 'quux' ); +ok( exists( ExtUtils::Manifest::manifind()->{$quux} ), "manifind found $quux" ); + +# only MANIFEST and foo are in the manifest +my $files = maniread(); +is( keys %$files, 2, 'two files found' ); +is( join(' ', sort keys %$files), 'MANIFEST foo', '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' ); + +ok( mkdir( 'copy', 0777 ), 'made copy directory' ); + +$files = maniread(); +eval { (undef, $warn) = catch_warning( sub { + manicopy( $files, 'copy', 'cp' ) }) +}; + +# 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: No such file or directory/, + 'carped about none' ); + +# tell ExtUtils::Manifest to use a different file +use vars qw($ExtUtils::Manifest::MANIFEST); +$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 +push @files, 'albatross'; + +END { + # the arrays are evaluated in scalar context + is( unlink( @files ), @files, 'remove all added files' ); + remove_dir( 'moretest', 'copy' ); + + # now get rid of the parent directory + ok( chdir( $cwd ), 'return to parent directory' ); + remove_dir( 'mantest' ); +}