MakeMaker 5.55_03 -> 5.90_01
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / Manifest.t
CommitLineData
f6d6199c 1#!/usr/bin/perl -w
0300da75 2
3BEGIN {
39234879 4 if( $ENV{PERL_CORE} ) {
5 chdir 't' if -d 't';
6 unshift @INC, '../lib';
7 }
f6d6199c 8 else {
9 unshift @INC, 't/lib';
10 }
0300da75 11}
39234879 12chdir 't';
0300da75 13
f6d6199c 14use strict;
15
0300da75 16# these files help the test run
f6d6199c 17use Test::More tests => 32;
0300da75 18use Cwd;
19
20# these files are needed for the module itself
21use File::Spec;
22use File::Path;
23use Carp::Heavy;
24
25# keep track of everything added so it can all be deleted
f6d6199c 26my %files;
0300da75 27sub add_file {
28 my ($file, $data) = @_;
29 $data ||= 'foo';
f6d6199c 30 unlink $file; # or else we'll get multiple versions on VMS
020b036f 31 open( my $T, '>', $file) or return;
0300da75 32 print $T $data;
f6d6199c 33 ++$files{$file};
0300da75 34}
35
36sub read_manifest {
37 open( my $M, 'MANIFEST' ) or return;
38 chomp( my @files = <$M> );
39 return @files;
40}
41
42sub catch_warning {
43 my $warn;
44 local $SIG{__WARN__} = sub { $warn .= $_[0] };
45 return join('', $_[0]->() ), $warn;
46}
47
48sub remove_dir {
49 ok( rmdir( $_ ), "remove $_ directory" ) for @_;
50}
51
52# use module, import functions
f6d6199c 53BEGIN {
54 use_ok( 'ExtUtils::Manifest',
55 qw( mkmanifest manicheck filecheck fullcheck
56 maniread manicopy skipcheck ) );
57}
0300da75 58
59my $cwd = Cwd::getcwd();
60
61# Just in case any old files were lying around.
62rmtree('mantest');
63
64ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
65ok( chdir( 'mantest' ), 'chdir() to mantest' );
66ok( add_file('foo'), 'add a temporary file' );
67
68# there shouldn't be a MANIFEST there
69my ($res, $warn) = catch_warning( \&mkmanifest );
f2e6bef3 70# Canonize the order.
f6d6199c 71$warn = join("", map { "$_|" }
72 sort { lc($a) cmp lc($b) } split /\r?\n/, $warn);
f2e6bef3 73is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
f6d6199c 74 "mkmanifest() displayed its additions" );
0300da75 75
76# and now you see it
77ok( -e 'MANIFEST', 'create MANIFEST file' );
78
79my @list = read_manifest();
80is( @list, 2, 'check files in MANIFEST' );
81ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
82
83# after adding bar, the MANIFEST is out of date
84ok( add_file( 'bar' ), 'add another file' );
85ok( ! manicheck(), 'MANIFEST now out of sync' );
86
87# it reports that bar has been added and throws a warning
88($res, $warn) = catch_warning( \&filecheck );
89
90like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
91is( $res, 'bar', 'bar reported as new' );
92
93# now quiet the warning that bar was added and test again
f6d6199c 94($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1;
95 catch_warning( \&skipcheck )
96 };
97cmp_ok( $warn, 'eq', '', 'disabled warnings' );
0300da75 98
f6d6199c 99# add a skip file with a rule to skip itself (and the nonexistent glob '*baz*')
0300da75 100add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
101
102# this'll skip the new file
f6d6199c 103($res, $warn) = catch_warning( \&skipcheck );
104like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' );
0300da75 105
106# I'm not sure why this should be... shouldn't $missing be the only one?
107my ($found, $missing );
108catch_warning( sub {
f6d6199c 109 ( $found, $missing ) = skipcheck()
0300da75 110});
111
112# nothing new should be found, bar should be skipped
113is( @$found, 0, 'no output here' );
114is( join( ' ', @$missing ), 'bar', 'listed skipped files' );
115
f6d6199c 116{
117 local $ExtUtils::Manifest::Quiet = 1;
118 is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
119}
0300da75 120
121# add a subdirectory and a file there that should be found
122ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
f6d6199c 123add_file( File::Spec->catfile('moretest', 'quux'), 'quux' );
124ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ),
125 "manifind found moretest/quux" );
0300da75 126
127# only MANIFEST and foo are in the manifest
128my $files = maniread();
129is( keys %$files, 2, 'two files found' );
f6d6199c 130is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST',
131 'both files found' );
0300da75 132
133# poison the manifest, and add a comment that should be reported
134add_file( 'MANIFEST', 'none #none' );
f6d6199c 135is( ExtUtils::Manifest::maniread()->{none}, '#none',
136 'maniread found comment' );
0300da75 137
138ok( mkdir( 'copy', 0777 ), 'made copy directory' );
139
140$files = maniread();
141eval { (undef, $warn) = catch_warning( sub {
142 manicopy( $files, 'copy', 'cp' ) })
143};
f6d6199c 144like( $@, qr/^Can't read none: /, 'carped about none' );
0300da75 145
146# a newline comes through, so get rid of it
147chomp($warn);
148
149# the copy should have given one warning and one error
f6d6199c 150like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' );
0300da75 151
152# tell ExtUtils::Manifest to use a different file
f6d6199c 153{
154 local $ExtUtils::Manifest::MANIFEST = 'albatross';
155 ($res, $warn) = catch_warning( \&mkmanifest );
156 like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
157
158 # add the new file to the list of files to be deleted
159 $files{'albatross'}++;
39234879 160}
0300da75 161
0300da75 162
f6d6199c 163# Make sure MANIFEST.SKIP is using complete relative paths
164add_file( 'MANIFEST.SKIP' => "^moretest/q\n" );
165
166# This'll skip moretest/quux
167($res, $warn) = catch_warning( \&skipcheck );
168like( $warn, qr{^Skipping moretest/quux}i, 'got skipping warning again' );
169
0300da75 170
171END {
f6d6199c 172 # the args are evaluated in scalar context
173 is( unlink( keys %files ), keys %files, 'remove all added files' );
0300da75 174 remove_dir( 'moretest', 'copy' );
175
176 # now get rid of the parent directory
177 ok( chdir( $cwd ), 'return to parent directory' );
349e1be1 178 unlink('mantest/MANIFEST');
0300da75 179 remove_dir( 'mantest' );
180}
349e1be1 181