4 if( $ENV{PERL_CORE} ) {
6 unshift @INC, '../lib';
16 use Test::More tests => 66;
24 my $Is_VMS = $^O eq 'VMS';
26 # We're going to be chdir'ing and modules are sometimes loaded on the
27 # fly in this test, so we need an absolute @INC.
28 @INC = map { File::Spec->rel2abs($_) } @INC;
30 # keep track of everything added so it can all be deleted
33 my ($file, $data) = @_;
35 1 while unlink $file; # or else we'll get multiple versions on VMS
36 open( T, '>'.$file) or return;
43 open( M, 'MANIFEST' ) or return;
44 chomp( my @files = <M> );
51 local $SIG{__WARN__} = sub { $warn .= $_[0] };
52 return join('', $_[0]->() ), $warn;
56 ok( rmdir( $_ ), "remove $_ directory" ) for @_;
59 # use module, import functions
61 use_ok( 'ExtUtils::Manifest',
62 qw( mkmanifest manicheck filecheck fullcheck
63 maniread manicopy skipcheck maniadd) );
66 my $cwd = Cwd::getcwd();
68 # Just in case any old files were lying around.
71 ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
72 ok( chdir( 'mantest' ), 'chdir() to mantest' );
73 ok( add_file('foo'), 'add a temporary file' );
75 # This ensures the -x check for manicopy means something
76 # Some platforms don't have chmod or an executable bit, in which case
77 # this call will do nothing or fail, but on the platforms where chmod()
78 # works, we test the executable bit is copied
79 chmod( 0744, 'foo') if $Config{'chmod'};
81 # there shouldn't be a MANIFEST there
82 my ($res, $warn) = catch_warning( \&mkmanifest );
84 $warn = join("", map { "$_|" }
85 sort { lc($a) cmp lc($b) } split /\r?\n/, $warn);
86 is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
87 "mkmanifest() displayed its additions" );
90 ok( -e 'MANIFEST', 'create MANIFEST file' );
92 my @list = read_manifest();
93 is( @list, 2, 'check files in MANIFEST' );
94 ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
96 # after adding bar, the MANIFEST is out of date
97 ok( add_file( 'bar' ), 'add another file' );
98 ok( ! manicheck(), 'MANIFEST now out of sync' );
100 # it reports that bar has been added and throws a warning
101 ($res, $warn) = catch_warning( \&filecheck );
103 like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
104 is( $res, 'bar', 'bar reported as new' );
106 # now quiet the warning that bar was added and test again
107 ($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1;
108 catch_warning( \&skipcheck )
110 is( $warn, '', 'disabled warnings' );
112 # add a skip file with a rule to skip itself (and the nonexistent glob '*baz*')
113 add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
115 # this'll skip the new file
116 ($res, $warn) = catch_warning( \&skipcheck );
117 like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' );
121 @skipped = skipcheck()
124 is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' );
127 local $ExtUtils::Manifest::Quiet = 1;
128 is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
131 # add a subdirectory and a file there that should be found
132 ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
133 add_file( File::Spec->catfile('moretest', 'quux'), 'quux' );
134 ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ),
135 "manifind found moretest/quux" );
137 # only MANIFEST and foo are in the manifest
139 my $files = maniread();
140 is( keys %$files, 2, 'two files found' );
141 is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST',
142 'both files found' );
143 is( $_, 'foo', q{maniread() doesn't clobber $_} );
145 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
147 # Check that manicopy copies files.
148 manicopy( $files, 'copy', 'cp' );
150 find( sub { push @copies, $_ if -f }, 'copy' );
151 @copies = map { s/\.$//; $_ } @copies if $Is_VMS; # VMS likes to put dots on
153 # Have to compare insensitively for non-case preserving VMS
154 is_deeply( [sort map { lc } @copies], [sort map { lc } keys %$files] );
156 # cp would leave files readonly, so check permissions.
157 foreach my $orig (@copies) {
158 my $copy = "copy/$orig";
159 ok( -r $copy, "$copy: must be readable" );
160 is( -w $copy, -w $orig, " writable if original was" );
161 is( -x $copy, -x $orig, " executable if original was" );
166 # poison the manifest, and add a comment that should be reported
167 add_file( 'MANIFEST', 'none #none' );
168 is( ExtUtils::Manifest::maniread()->{none}, '#none',
169 'maniread found comment' );
171 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
173 eval { (undef, $warn) = catch_warning( sub {
174 manicopy( $files, 'copy', 'cp' ) })
176 like( $@, qr/^Can't read none: /, 'croaked about none' );
178 # a newline comes through, so get rid of it
181 # the copy should have given one warning and one error
182 like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' );
184 # tell ExtUtils::Manifest to use a different file
186 local $ExtUtils::Manifest::MANIFEST = 'albatross';
187 ($res, $warn) = catch_warning( \&mkmanifest );
188 like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
190 # add the new file to the list of files to be deleted
191 $Files{'albatross'}++;
195 # Make sure MANIFEST.SKIP is using complete relative paths
196 add_file( 'MANIFEST.SKIP' => "^moretest/q\n" );
198 # This'll skip moretest/quux
199 ($res, $warn) = catch_warning( \&skipcheck );
200 like( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' );
203 # There was a bug where entries in MANIFEST would be blotted out
204 # by MANIFEST.SKIP rules.
205 add_file( 'MANIFEST.SKIP' => 'foo' );
206 add_file( 'MANIFEST' => "foobar\n" );
207 add_file( 'foobar' => '123' );
208 ($res, $warn) = catch_warning( \&manicheck );
209 is( $res, '', 'MANIFEST overrides MANIFEST.SKIP' );
210 is( $warn, '', 'MANIFEST overrides MANIFEST.SKIP, no warnings' );
213 ok( !$files->{wibble}, 'MANIFEST in good state' );
214 maniadd({ wibble => undef });
215 maniadd({ yarrow => "hock" });
217 is( $files->{wibble}, '', 'maniadd() with undef comment' );
218 is( $files->{yarrow}, 'hock',' with comment' );
219 is( $files->{foobar}, '', ' preserved old entries' );
221 # test including an external manifest.skip file in MANIFEST.SKIP
223 maniadd({ foo => undef , albatross => undef,
224 'mymanifest.skip' => undef, 'mydefault.skip' => undef});
225 add_file('mymanifest.skip' => "^foo\n");
226 add_file('mydefault.skip' => "^my\n");
227 $ExtUtils::Manifest::DEFAULT_MSKIP =
228 File::Spec->catfile($cwd, qw(mantest mydefault.skip));
229 my $skip = File::Spec->catfile($cwd, qw(mantest mymanifest.skip));
230 add_file('MANIFEST.SKIP' =>
231 "albatross\n#!include $skip\n#!include_default");
232 my ($res, $warn) = catch_warning( \&skipcheck );
233 for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) {
234 like( $warn, qr/Skipping \b$_\b/,
237 ($res, $warn) = catch_warning( \&mkmanifest );
238 for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) {
239 like( $warn, qr/Removed from MANIFEST: \b$_\b/,
240 "Removed $_ from MANIFEST" );
242 my $files = maniread;
243 ok( ! exists $files->{albatross}, 'albatross excluded via MANIFEST.SKIP' );
244 ok( exists $files->{yarrow}, 'yarrow included in MANIFEST' );
245 ok( exists $files->{bar}, 'bar included in MANIFEST' );
246 ok( ! exists $files->{foobar}, 'foobar excluded via mymanifest.skip' );
247 ok( ! exists $files->{foo}, 'foo excluded via mymanifest.skip' );
248 ok( ! exists $files->{'mymanifest.skip'},
249 'mymanifest.skip excluded via mydefault.skip' );
250 ok( ! exists $files->{'mydefault.skip'},
251 'mydefault.skip excluded via mydefault.skip' );
252 my $extsep = $Is_VMS ? '_' : '.';
253 $Files{"$_.bak"}++ for ('MANIFEST', "MANIFEST${extsep}SKIP");
256 add_file('MANIFEST' => 'Makefile.PL');
257 maniadd({ foo => 'bar' });
259 # VMS downcases the MANIFEST. We normalize it here to match.
260 %$files = map { (lc $_ => $files->{$_}) } keys %$files;
261 my %expect = ( 'makefile.pl' => '',
264 is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline');
266 #add_file('MANIFEST' => 'Makefile.PL');
267 #maniadd({ foo => 'bar' });
270 chmod( 0400, 'MANIFEST' );
271 skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST';
274 maniadd({ 'foo' => 'bar' });
276 is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" );
279 maniadd({ 'grrrwoof' => 'yippie' });
281 like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/,
282 "maniadd() dies if it can't open the MANIFEST" );
284 chmod( 0600, 'MANIFEST' );
289 is( unlink( keys %Files ), keys %Files, 'remove all added files' );
290 remove_dir( 'moretest', 'copy' );
292 # now get rid of the parent directory
293 ok( chdir( $cwd ), 'return to parent directory' );
294 remove_dir( 'mantest' );