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 unshift @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-gatechdir 't'; 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gateuse strict; 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gate# these files help the test run 17*0Sstevel@tonic-gateuse Test::More tests => 41; 18*0Sstevel@tonic-gateuse Cwd; 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gate# these files are needed for the module itself 21*0Sstevel@tonic-gateuse File::Spec; 22*0Sstevel@tonic-gateuse File::Path; 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gate# We're going to be chdir'ing and modules are sometimes loaded on the 25*0Sstevel@tonic-gate# fly in this test, so we need an absolute @INC. 26*0Sstevel@tonic-gate@INC = map { File::Spec->rel2abs($_) } @INC; 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate# keep track of everything added so it can all be deleted 29*0Sstevel@tonic-gatemy %Files; 30*0Sstevel@tonic-gatesub add_file { 31*0Sstevel@tonic-gate my ($file, $data) = @_; 32*0Sstevel@tonic-gate $data ||= 'foo'; 33*0Sstevel@tonic-gate 1 while unlink $file; # or else we'll get multiple versions on VMS 34*0Sstevel@tonic-gate open( T, '>'.$file) or return; 35*0Sstevel@tonic-gate print T $data; 36*0Sstevel@tonic-gate ++$Files{$file}; 37*0Sstevel@tonic-gate close T; 38*0Sstevel@tonic-gate} 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gatesub read_manifest { 41*0Sstevel@tonic-gate open( M, 'MANIFEST' ) or return; 42*0Sstevel@tonic-gate chomp( my @files = <M> ); 43*0Sstevel@tonic-gate close M; 44*0Sstevel@tonic-gate return @files; 45*0Sstevel@tonic-gate} 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gatesub catch_warning { 48*0Sstevel@tonic-gate my $warn; 49*0Sstevel@tonic-gate local $SIG{__WARN__} = sub { $warn .= $_[0] }; 50*0Sstevel@tonic-gate return join('', $_[0]->() ), $warn; 51*0Sstevel@tonic-gate} 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gatesub remove_dir { 54*0Sstevel@tonic-gate ok( rmdir( $_ ), "remove $_ directory" ) for @_; 55*0Sstevel@tonic-gate} 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate# use module, import functions 58*0Sstevel@tonic-gateBEGIN { 59*0Sstevel@tonic-gate use_ok( 'ExtUtils::Manifest', 60*0Sstevel@tonic-gate qw( mkmanifest manicheck filecheck fullcheck 61*0Sstevel@tonic-gate maniread manicopy skipcheck maniadd) ); 62*0Sstevel@tonic-gate} 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gatemy $cwd = Cwd::getcwd(); 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate# Just in case any old files were lying around. 67*0Sstevel@tonic-gatermtree('mantest'); 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gateok( mkdir( 'mantest', 0777 ), 'make mantest directory' ); 70*0Sstevel@tonic-gateok( chdir( 'mantest' ), 'chdir() to mantest' ); 71*0Sstevel@tonic-gateok( add_file('foo'), 'add a temporary file' ); 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate# there shouldn't be a MANIFEST there 74*0Sstevel@tonic-gatemy ($res, $warn) = catch_warning( \&mkmanifest ); 75*0Sstevel@tonic-gate# Canonize the order. 76*0Sstevel@tonic-gate$warn = join("", map { "$_|" } 77*0Sstevel@tonic-gate sort { lc($a) cmp lc($b) } split /\r?\n/, $warn); 78*0Sstevel@tonic-gateis( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|", 79*0Sstevel@tonic-gate "mkmanifest() displayed its additions" ); 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate# and now you see it 82*0Sstevel@tonic-gateok( -e 'MANIFEST', 'create MANIFEST file' ); 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gatemy @list = read_manifest(); 85*0Sstevel@tonic-gateis( @list, 2, 'check files in MANIFEST' ); 86*0Sstevel@tonic-gateok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' ); 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate# after adding bar, the MANIFEST is out of date 89*0Sstevel@tonic-gateok( add_file( 'bar' ), 'add another file' ); 90*0Sstevel@tonic-gateok( ! manicheck(), 'MANIFEST now out of sync' ); 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate# it reports that bar has been added and throws a warning 93*0Sstevel@tonic-gate($res, $warn) = catch_warning( \&filecheck ); 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gatelike( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' ); 96*0Sstevel@tonic-gateis( $res, 'bar', 'bar reported as new' ); 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate# now quiet the warning that bar was added and test again 99*0Sstevel@tonic-gate($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1; 100*0Sstevel@tonic-gate catch_warning( \&skipcheck ) 101*0Sstevel@tonic-gate }; 102*0Sstevel@tonic-gatecmp_ok( $warn, 'eq', '', 'disabled warnings' ); 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate# add a skip file with a rule to skip itself (and the nonexistent glob '*baz*') 105*0Sstevel@tonic-gateadd_file( 'MANIFEST.SKIP', "baz\n.SKIP" ); 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate# this'll skip the new file 108*0Sstevel@tonic-gate($res, $warn) = catch_warning( \&skipcheck ); 109*0Sstevel@tonic-gatelike( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' ); 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gatemy @skipped; 112*0Sstevel@tonic-gatecatch_warning( sub { 113*0Sstevel@tonic-gate @skipped = skipcheck() 114*0Sstevel@tonic-gate}); 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gateis( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' ); 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate{ 119*0Sstevel@tonic-gate local $ExtUtils::Manifest::Quiet = 1; 120*0Sstevel@tonic-gate is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' ); 121*0Sstevel@tonic-gate} 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate# add a subdirectory and a file there that should be found 124*0Sstevel@tonic-gateok( mkdir( 'moretest', 0777 ), 'created moretest directory' ); 125*0Sstevel@tonic-gateadd_file( File::Spec->catfile('moretest', 'quux'), 'quux' ); 126*0Sstevel@tonic-gateok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ), 127*0Sstevel@tonic-gate "manifind found moretest/quux" ); 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate# only MANIFEST and foo are in the manifest 130*0Sstevel@tonic-gate$_ = 'foo'; 131*0Sstevel@tonic-gatemy $files = maniread(); 132*0Sstevel@tonic-gateis( keys %$files, 2, 'two files found' ); 133*0Sstevel@tonic-gateis( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST', 134*0Sstevel@tonic-gate 'both files found' ); 135*0Sstevel@tonic-gateis( $_, 'foo', q{maniread() doesn't clobber $_} ); 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate# poison the manifest, and add a comment that should be reported 138*0Sstevel@tonic-gateadd_file( 'MANIFEST', 'none #none' ); 139*0Sstevel@tonic-gateis( ExtUtils::Manifest::maniread()->{none}, '#none', 140*0Sstevel@tonic-gate 'maniread found comment' ); 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gateok( mkdir( 'copy', 0777 ), 'made copy directory' ); 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate$files = maniread(); 145*0Sstevel@tonic-gateeval { (undef, $warn) = catch_warning( sub { 146*0Sstevel@tonic-gate manicopy( $files, 'copy', 'cp' ) }) 147*0Sstevel@tonic-gate}; 148*0Sstevel@tonic-gatelike( $@, qr/^Can't read none: /, 'croaked about none' ); 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate# a newline comes through, so get rid of it 151*0Sstevel@tonic-gatechomp($warn); 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate# the copy should have given one warning and one error 154*0Sstevel@tonic-gatelike($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' ); 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate# tell ExtUtils::Manifest to use a different file 157*0Sstevel@tonic-gate{ 158*0Sstevel@tonic-gate local $ExtUtils::Manifest::MANIFEST = 'albatross'; 159*0Sstevel@tonic-gate ($res, $warn) = catch_warning( \&mkmanifest ); 160*0Sstevel@tonic-gate like( $warn, qr/Added to albatross: /, 'using a new manifest file' ); 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate # add the new file to the list of files to be deleted 163*0Sstevel@tonic-gate $Files{'albatross'}++; 164*0Sstevel@tonic-gate} 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate# Make sure MANIFEST.SKIP is using complete relative paths 168*0Sstevel@tonic-gateadd_file( 'MANIFEST.SKIP' => "^moretest/q\n" ); 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate# This'll skip moretest/quux 171*0Sstevel@tonic-gate($res, $warn) = catch_warning( \&skipcheck ); 172*0Sstevel@tonic-gatelike( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' ); 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate# There was a bug where entries in MANIFEST would be blotted out 176*0Sstevel@tonic-gate# by MANIFEST.SKIP rules. 177*0Sstevel@tonic-gateadd_file( 'MANIFEST.SKIP' => 'foo' ); 178*0Sstevel@tonic-gateadd_file( 'MANIFEST' => "foobar\n" ); 179*0Sstevel@tonic-gateadd_file( 'foobar' => '123' ); 180*0Sstevel@tonic-gate($res, $warn) = catch_warning( \&manicheck ); 181*0Sstevel@tonic-gateis( $res, '', 'MANIFEST overrides MANIFEST.SKIP' ); 182*0Sstevel@tonic-gateis( $warn, undef, 'MANIFEST overrides MANIFEST.SKIP, no warnings' ); 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate$files = maniread; 185*0Sstevel@tonic-gateok( !$files->{wibble}, 'MANIFEST in good state' ); 186*0Sstevel@tonic-gatemaniadd({ wibble => undef }); 187*0Sstevel@tonic-gatemaniadd({ yarrow => "hock" }); 188*0Sstevel@tonic-gate$files = maniread; 189*0Sstevel@tonic-gateis( $files->{wibble}, '', 'maniadd() with undef comment' ); 190*0Sstevel@tonic-gateis( $files->{yarrow}, 'hock',' with comment' ); 191*0Sstevel@tonic-gateis( $files->{foobar}, '', ' preserved old entries' ); 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gateadd_file('MANIFEST' => 'Makefile.PL'); 194*0Sstevel@tonic-gatemaniadd({ foo => 'bar' }); 195*0Sstevel@tonic-gate$files = maniread; 196*0Sstevel@tonic-gate# VMS downcases the MANIFEST. We normalize it here to match. 197*0Sstevel@tonic-gate%$files = map { (lc $_ => $files->{$_}) } keys %$files; 198*0Sstevel@tonic-gatemy %expect = ( 'makefile.pl' => '', 199*0Sstevel@tonic-gate 'foo' => 'bar' 200*0Sstevel@tonic-gate ); 201*0Sstevel@tonic-gateis_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline'); 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gateadd_file('MANIFEST' => 'Makefile.PL'); 204*0Sstevel@tonic-gatemaniadd({ foo => 'bar' }); 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gateSKIP: { 207*0Sstevel@tonic-gate chmod( 0400, 'MANIFEST' ); 208*0Sstevel@tonic-gate skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST'; 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate eval { 211*0Sstevel@tonic-gate maniadd({ 'foo' => 'bar' }); 212*0Sstevel@tonic-gate }; 213*0Sstevel@tonic-gate is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" ); 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate eval { 216*0Sstevel@tonic-gate maniadd({ 'grrrwoof' => 'yippie' }); 217*0Sstevel@tonic-gate }; 218*0Sstevel@tonic-gate like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/, 219*0Sstevel@tonic-gate "maniadd() dies if it can't open the MANIFEST" ); 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate chmod( 0600, 'MANIFEST' ); 222*0Sstevel@tonic-gate} 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gateEND { 226*0Sstevel@tonic-gate is( unlink( keys %Files ), keys %Files, 'remove all added files' ); 227*0Sstevel@tonic-gate remove_dir( 'moretest', 'copy' ); 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate # now get rid of the parent directory 230*0Sstevel@tonic-gate ok( chdir( $cwd ), 'return to parent directory' ); 231*0Sstevel@tonic-gate remove_dir( 'mantest' ); 232*0Sstevel@tonic-gate} 233*0Sstevel@tonic-gate 234