4 if( $ENV{PERL_CORE} ) {
6 unshift @INC, '../lib';
16 use Test::More tests => 94;
24 my $Is_VMS = $^O eq 'VMS';
25 my $Is_VMS_noefs = $Is_VMS;
28 if (eval 'require VMS::Feature') {
29 $vms_efs = VMS::Feature::current("efs_charset");
31 my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
32 $vms_efs = $efs_charset =~ /^[ET1]/i;
34 $Is_VMS_noefs = 0 if $vms_efs;
38 # We're going to be chdir'ing and modules are sometimes loaded on the
39 # fly in this test, so we need an absolute @INC.
40 @INC = map { File::Spec->rel2abs($_) } @INC;
42 # keep track of everything added so it can all be deleted
45 my ($file, $data) = @_;
47 1 while unlink $file; # or else we'll get multiple versions on VMS
48 open( T, '> '.$file) or return;
51 return 0 unless -e $file; # exists under the name we gave it ?
56 open( M, 'MANIFEST' ) or return;
57 chomp( my @files = <M> );
64 local $SIG{__WARN__} = sub { $warn .= $_[0] };
65 return join('', $_[0]->() ), $warn;
69 ok( rmdir( $_ ), "remove $_ directory" ) for @_;
72 # use module, import functions
74 use_ok( 'ExtUtils::Manifest',
75 qw( mkmanifest manicheck filecheck fullcheck
76 maniread manicopy skipcheck maniadd maniskip) );
79 my $cwd = Cwd::getcwd();
81 # Just in case any old files were lying around.
84 ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
85 ok( chdir( 'mantest' ), 'chdir() to mantest' );
86 ok( add_file('foo'), 'add a temporary file' );
88 # This ensures the -x check for manicopy means something
89 # Some platforms don't have chmod or an executable bit, in which case
90 # this call will do nothing or fail, but on the platforms where chmod()
91 # works, we test the executable bit is copied
92 chmod( 0744, 'foo') if $Config{'chmod'};
94 # there shouldn't be a MANIFEST there
95 my ($res, $warn) = catch_warning( \&mkmanifest );
97 $warn = join("", map { "$_|" }
98 sort { lc($a) cmp lc($b) } split /\r?\n/, $warn);
99 is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
100 "mkmanifest() displayed its additions" );
103 ok( -e 'MANIFEST', 'create MANIFEST file' );
105 my @list = read_manifest();
106 is( @list, 2, 'check files in MANIFEST' );
107 ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
109 # after adding bar, the MANIFEST is out of date
110 ok( add_file( 'bar' ), 'add another file' );
111 ok( ! manicheck(), 'MANIFEST now out of sync' );
113 # it reports that bar has been added and throws a warning
114 ($res, $warn) = catch_warning( \&filecheck );
116 like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
117 is( $res, 'bar', 'bar reported as new' );
119 # now quiet the warning that bar was added and test again
120 ($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1;
121 catch_warning( \&skipcheck )
123 is( $warn, '', 'disabled warnings' );
125 # add a skip file with a rule to skip itself (and the nonexistent glob '*baz*')
126 add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
128 # this'll skip the new file
129 ($res, $warn) = catch_warning( \&skipcheck );
130 like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' );
134 @skipped = skipcheck()
137 is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' );
140 local $ExtUtils::Manifest::Quiet = 1;
141 is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
144 # add a subdirectory and a file there that should be found
145 ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
146 add_file( File::Spec->catfile('moretest', 'quux'), 'quux' );
147 ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ),
148 "manifind found moretest/quux" );
150 # only MANIFEST and foo are in the manifest
152 my $files = maniread();
153 is( keys %$files, 2, 'two files found' );
154 is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST',
155 'both files found' );
156 is( $_, 'foo', q{maniread() doesn't clobber $_} );
158 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
160 # Check that manicopy copies files.
161 manicopy( $files, 'copy', 'cp' );
163 find( sub { push @copies, $_ if -f }, 'copy' );
164 @copies = map { s/\.$//; $_ } @copies if $Is_VMS; # VMS likes to put dots on
166 # Have to compare insensitively for non-case preserving VMS
167 is_deeply( [sort map { lc } @copies], [sort map { lc } keys %$files] );
169 # cp would leave files readonly, so check permissions.
170 foreach my $orig (@copies) {
171 my $copy = "copy/$orig";
172 ok( -r $copy, "$copy: must be readable" );
173 is( -w $copy, -w $orig, " writable if original was" );
174 is( -x $copy, -x $orig, " executable if original was" );
179 # poison the manifest, and add a comment that should be reported
180 add_file( 'MANIFEST', 'none #none' );
181 is( ExtUtils::Manifest::maniread()->{none}, '#none',
182 'maniread found comment' );
184 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
186 eval { (undef, $warn) = catch_warning( sub {
187 manicopy( $files, 'copy', 'cp' ) })
190 # a newline comes through, so get rid of it
192 # the copy should have given a warning
193 like($warn, qr/^none not found/, 'carped about none' );
194 ($res, $warn) = catch_warning( \&skipcheck );
195 like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' );
197 # tell ExtUtils::Manifest to use a different file
199 local $ExtUtils::Manifest::MANIFEST = 'albatross';
200 ($res, $warn) = catch_warning( \&mkmanifest );
201 like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
203 # add the new file to the list of files to be deleted
204 $Files{'albatross'}++;
208 # Make sure MANIFEST.SKIP is using complete relative paths
209 add_file( 'MANIFEST.SKIP' => "^moretest/q\n" );
211 # This'll skip moretest/quux
212 ($res, $warn) = catch_warning( \&skipcheck );
213 like( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' );
216 # There was a bug where entries in MANIFEST would be blotted out
217 # by MANIFEST.SKIP rules.
218 add_file( 'MANIFEST.SKIP' => 'foo' );
219 add_file( 'MANIFEST' => "foobar\n" );
220 add_file( 'foobar' => '123' );
221 ($res, $warn) = catch_warning( \&manicheck );
222 is( $res, '', 'MANIFEST overrides MANIFEST.SKIP' );
223 is( $warn, '', 'MANIFEST overrides MANIFEST.SKIP, no warnings' );
226 ok( !$files->{wibble}, 'MANIFEST in good state' );
227 maniadd({ wibble => undef });
228 maniadd({ yarrow => "hock" });
230 is( $files->{wibble}, '', 'maniadd() with undef comment' );
231 is( $files->{yarrow}, 'hock',' with comment' );
232 is( $files->{foobar}, '', ' preserved old entries' );
235 # test including a filename with a space
237 add_file( 'foo bar' => "space" )
238 or skip "couldn't create spaced test file", 2;
239 local $ExtUtils::Manifest::MANIFEST = "albatross";
240 maniadd({ 'foo bar' => "contains space"});
241 is( maniread()->{'foo bar'}, "contains space",
242 'spaced manifest filename' );
243 add_file( 'albatross.bak', '' );
244 ($res, $warn) = catch_warning( \&mkmanifest );
245 like( $warn, qr/\A(Added to.*\n)+\z/m,
246 'no warnings about funky filename' );
247 $funky_files{'space'} = 'foo bar';
250 # test including a filename with a space and a quote
252 add_file( 'foo\' baz\'quux' => "quote" )
253 or skip "couldn't create quoted test file", 1;
254 local $ExtUtils::Manifest::MANIFEST = "albatross";
255 maniadd({ 'foo\' baz\'quux' => "contains quote"});
256 is( maniread()->{'foo\' baz\'quux'}, "contains quote",
257 'quoted manifest filename' );
258 $funky_files{'space_quote'} = 'foo\' baz\'quux';
261 # test including a filename with a space and a backslash
263 add_file( 'foo bar\\baz' => "backslash" )
264 or skip "couldn't create backslash test file", 1;
265 local $ExtUtils::Manifest::MANIFEST = "albatross";
266 maniadd({ 'foo bar\\baz' => "contains backslash"});
267 is( maniread()->{'foo bar\\baz'}, "contains backslash",
268 'backslashed manifest filename' );
269 $funky_files{'space_backslash'} = 'foo bar\\baz';
272 # test including a filename with a space, quote, and a backslash
274 add_file( 'foo bar\\baz\'quux' => "backslash/quote" )
275 or skip "couldn't create backslash/quote test file", 1;
276 local $ExtUtils::Manifest::MANIFEST = "albatross";
277 maniadd({ 'foo bar\\baz\'quux' => "backslash and quote"});
278 is( maniread()->{'foo bar\\baz\'quux'}, "backslash and quote",
279 'backslashed and quoted manifest filename' );
280 $funky_files{'space_quote_backslash'} = 'foo bar\\baz\'quux';
283 my @funky_keys = qw(space space_quote space_backslash space_quote_backslash);
284 # test including an external manifest.skip file in MANIFEST.SKIP
286 maniadd({ foo => undef , albatross => undef,
287 'mymanifest.skip' => undef, 'mydefault.skip' => undef});
289 maniadd( {$funky_files{$_} => $_} ) if defined $funky_files{$_};
292 add_file('mymanifest.skip' => "^foo\n");
293 add_file('mydefault.skip' => "^my\n");
294 local $ExtUtils::Manifest::DEFAULT_MSKIP =
295 File::Spec->catfile($cwd, qw(mantest mydefault.skip));
296 my $skip = File::Spec->catfile($cwd, qw(mantest mymanifest.skip));
297 add_file('MANIFEST.SKIP' =>
298 "albatross\n#!include $skip\n#!include_default");
299 my ($res, $warn) = catch_warning( \&skipcheck );
300 for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) {
301 like( $warn, qr/Skipping \b$_\b/,
304 for my $funky_key (@funky_keys) {
306 my $funky_file = $funky_files{$funky_key};
307 skip "'$funky_key' not created", 1 unless $funky_file;
308 like( $warn, qr/Skipping \b\Q$funky_file\E\b/,
309 "Skipping $funky_file");
312 ($res, $warn) = catch_warning( \&mkmanifest );
313 for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) {
314 like( $warn, qr/Removed from MANIFEST: \b$_\b/,
315 "Removed $_ from MANIFEST" );
317 for my $funky_key (@funky_keys) {
319 my $funky_file = $funky_files{$funky_key};
320 skip "'$funky_key' not created", 1 unless $funky_file;
321 like( $warn, qr/Removed from MANIFEST: \b\Q$funky_file\E\b/,
322 "Removed $funky_file from MANIFEST");
325 my $files = maniread;
326 ok( ! exists $files->{albatross}, 'albatross excluded via MANIFEST.SKIP' );
327 ok( exists $files->{yarrow}, 'yarrow included in MANIFEST' );
328 ok( exists $files->{bar}, 'bar included in MANIFEST' );
329 ok( ! exists $files->{foobar}, 'foobar excluded via mymanifest.skip' );
330 ok( ! exists $files->{foo}, 'foo excluded via mymanifest.skip' );
331 ok( ! exists $files->{'mymanifest.skip'},
332 'mymanifest.skip excluded via mydefault.skip' );
333 ok( ! exists $files->{'mydefault.skip'},
334 'mydefault.skip excluded via mydefault.skip' );
336 # test exclusion of funky files
337 for my $funky_key (@funky_keys) {
339 my $funky_file = $funky_files{$funky_key};
340 skip "'$funky_key' not created", 1 unless $funky_file;
341 ok( ! exists $files->{$funky_file},
342 "'$funky_file' excluded via mymanifest.skip" );
347 my $skipchk = maniskip();
348 is ( $skipchk->('albatross'), 1,
349 'albatross excluded via MANIFEST.SKIP' );
350 is( $skipchk->('yarrow'), '',
351 'yarrow included in MANIFEST' );
352 is( $skipchk->('bar'), '',
353 'bar included in MANIFEST' );
354 $skipchk = maniskip('mymanifest.skip');
355 is( $skipchk->('foobar'), 1,
356 'foobar excluded via mymanifest.skip' );
357 is( $skipchk->('foo'), 1,
358 'foo excluded via mymanifest.skip' );
359 is( $skipchk->('mymanifest.skip'), '',
360 'mymanifest.skip included via mydefault.skip' );
361 is( $skipchk->('mydefault.skip'), '',
362 'mydefault.skip included via mydefault.skip' );
363 $skipchk = maniskip('mydefault.skip');
364 is( $skipchk->('foobar'), '',
365 'foobar included via mydefault.skip' );
366 is( $skipchk->('foo'), '',
367 'foo included via mydefault.skip' );
368 is( $skipchk->('mymanifest.skip'), 1,
369 'mymanifest.skip excluded via mydefault.skip' );
370 is( $skipchk->('mydefault.skip'), 1,
371 'mydefault.skip excluded via mydefault.skip' );
373 my $extsep = $Is_VMS_noefs ? '_' : '.';
374 $Files{"$_.bak"}++ for ('MANIFEST', "MANIFEST${extsep}SKIP");
377 add_file('MANIFEST' => 'Makefile.PL');
378 maniadd({ foo => 'bar' });
380 # VMS downcases the MANIFEST. We normalize it here to match.
381 %$files = map { (lc $_ => $files->{$_}) } keys %$files;
382 my %expect = ( 'makefile.pl' => '',
385 is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline');
387 #add_file('MANIFEST' => 'Makefile.PL');
388 #maniadd({ foo => 'bar' });
391 chmod( 0400, 'MANIFEST' );
392 skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST';
395 maniadd({ 'foo' => 'bar' });
397 is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" );
400 maniadd({ 'grrrwoof' => 'yippie' });
402 like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/,
403 "maniadd() dies if it can't open the MANIFEST" );
405 chmod( 0600, 'MANIFEST' );
410 is( unlink( keys %Files ), keys %Files, 'remove all added files' );
411 remove_dir( 'moretest', 'copy' );
413 # now get rid of the parent directory
414 ok( chdir( $cwd ), 'return to parent directory' );
415 remove_dir( 'mantest' );