Commit | Line | Data |
f6d6199c |
1 | #!/usr/bin/perl -w |
0300da75 |
2 | |
3 | BEGIN { |
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 |
12 | chdir 't'; |
0300da75 |
13 | |
f6d6199c |
14 | use strict; |
15 | |
6dbcfe36 |
16 | use Test::More tests => 94; |
0300da75 |
17 | use Cwd; |
18 | |
0300da75 |
19 | use File::Spec; |
20 | use File::Path; |
a7d1454b |
21 | use File::Find; |
1c14aae0 |
22 | use Config; |
a7d1454b |
23 | |
24 | my $Is_VMS = $^O eq 'VMS'; |
7e4d7138 |
25 | my $Is_VMS_noefs = $Is_VMS; |
26 | if ($Is_VMS) { |
27 | my $vms_efs = 0; |
28 | if (eval 'require VMS::Feature') { |
29 | $vms_efs = VMS::Feature::current("efs_charset"); |
30 | } else { |
31 | my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || ''; |
32 | $vms_efs = $efs_charset =~ /^[ET1]/i; |
33 | } |
34 | $Is_VMS_noefs = 0 if $vms_efs; |
35 | } |
36 | |
57b1a898 |
37 | |
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; |
0300da75 |
41 | |
42 | # keep track of everything added so it can all be deleted |
2530b651 |
43 | my %Files; |
0300da75 |
44 | sub add_file { |
479d2113 |
45 | my ($file, $data) = @_; |
46 | $data ||= 'foo'; |
2530b651 |
47 | 1 while unlink $file; # or else we'll get multiple versions on VMS |
6dbcfe36 |
48 | open( T, '> '.$file) or return; |
479d2113 |
49 | print T $data; |
57b1a898 |
50 | close T; |
7a5ea4ae |
51 | return 0 unless -e $file; # exists under the name we gave it ? |
52 | ++$Files{$file}; |
0300da75 |
53 | } |
54 | |
55 | sub read_manifest { |
a7d1454b |
56 | open( M, 'MANIFEST' ) or return; |
57 | chomp( my @files = <M> ); |
57b1a898 |
58 | close M; |
a7d1454b |
59 | return @files; |
0300da75 |
60 | } |
61 | |
62 | sub catch_warning { |
b3217f3b |
63 | my $warn = ''; |
a7d1454b |
64 | local $SIG{__WARN__} = sub { $warn .= $_[0] }; |
65 | return join('', $_[0]->() ), $warn; |
0300da75 |
66 | } |
67 | |
68 | sub remove_dir { |
a7d1454b |
69 | ok( rmdir( $_ ), "remove $_ directory" ) for @_; |
0300da75 |
70 | } |
71 | |
72 | # use module, import functions |
f6d6199c |
73 | BEGIN { |
74 | use_ok( 'ExtUtils::Manifest', |
75 | qw( mkmanifest manicheck filecheck fullcheck |
6dbcfe36 |
76 | maniread manicopy skipcheck maniadd maniskip) ); |
f6d6199c |
77 | } |
0300da75 |
78 | |
79 | my $cwd = Cwd::getcwd(); |
80 | |
81 | # Just in case any old files were lying around. |
82 | rmtree('mantest'); |
83 | |
84 | ok( mkdir( 'mantest', 0777 ), 'make mantest directory' ); |
85 | ok( chdir( 'mantest' ), 'chdir() to mantest' ); |
86 | ok( add_file('foo'), 'add a temporary file' ); |
87 | |
1c14aae0 |
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'}; |
93 | |
0300da75 |
94 | # there shouldn't be a MANIFEST there |
b3217f3b |
95 | my ($res, $warn) = catch_warning( \&mkmanifest ); |
f2e6bef3 |
96 | # Canonize the order. |
f6d6199c |
97 | $warn = join("", map { "$_|" } |
98 | sort { lc($a) cmp lc($b) } split /\r?\n/, $warn); |
f2e6bef3 |
99 | is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|", |
f6d6199c |
100 | "mkmanifest() displayed its additions" ); |
0300da75 |
101 | |
102 | # and now you see it |
103 | ok( -e 'MANIFEST', 'create MANIFEST file' ); |
104 | |
105 | my @list = read_manifest(); |
106 | is( @list, 2, 'check files in MANIFEST' ); |
107 | ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' ); |
108 | |
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' ); |
112 | |
113 | # it reports that bar has been added and throws a warning |
114 | ($res, $warn) = catch_warning( \&filecheck ); |
115 | |
116 | like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' ); |
117 | is( $res, 'bar', 'bar reported as new' ); |
118 | |
119 | # now quiet the warning that bar was added and test again |
b3217f3b |
120 | ($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1; |
121 | catch_warning( \&skipcheck ) |
f6d6199c |
122 | }; |
b3217f3b |
123 | is( $warn, '', 'disabled warnings' ); |
0300da75 |
124 | |
f6d6199c |
125 | # add a skip file with a rule to skip itself (and the nonexistent glob '*baz*') |
0300da75 |
126 | add_file( 'MANIFEST.SKIP', "baz\n.SKIP" ); |
127 | |
128 | # this'll skip the new file |
f6d6199c |
129 | ($res, $warn) = catch_warning( \&skipcheck ); |
130 | like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' ); |
0300da75 |
131 | |
45bc4d3a |
132 | my @skipped; |
0300da75 |
133 | catch_warning( sub { |
4c857482 |
134 | @skipped = skipcheck() |
0300da75 |
135 | }); |
136 | |
45bc4d3a |
137 | is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' ); |
0300da75 |
138 | |
f6d6199c |
139 | { |
140 | local $ExtUtils::Manifest::Quiet = 1; |
141 | is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' ); |
142 | } |
0300da75 |
143 | |
144 | # add a subdirectory and a file there that should be found |
145 | ok( mkdir( 'moretest', 0777 ), 'created moretest directory' ); |
f6d6199c |
146 | add_file( File::Spec->catfile('moretest', 'quux'), 'quux' ); |
147 | ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ), |
148 | "manifind found moretest/quux" ); |
0300da75 |
149 | |
150 | # only MANIFEST and foo are in the manifest |
2530b651 |
151 | $_ = 'foo'; |
0300da75 |
152 | my $files = maniread(); |
153 | is( keys %$files, 2, 'two files found' ); |
f6d6199c |
154 | is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST', |
155 | 'both files found' ); |
2530b651 |
156 | is( $_, 'foo', q{maniread() doesn't clobber $_} ); |
0300da75 |
157 | |
a7d1454b |
158 | ok( mkdir( 'copy', 0777 ), 'made copy directory' ); |
159 | |
160 | # Check that manicopy copies files. |
161 | manicopy( $files, 'copy', 'cp' ); |
162 | my @copies = (); |
163 | find( sub { push @copies, $_ if -f }, 'copy' ); |
164 | @copies = map { s/\.$//; $_ } @copies if $Is_VMS; # VMS likes to put dots on |
165 | # the end of files. |
166 | # Have to compare insensitively for non-case preserving VMS |
167 | is_deeply( [sort map { lc } @copies], [sort map { lc } keys %$files] ); |
168 | |
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" ); |
4c857482 |
173 | is( -w $copy, -w $orig, " writable if original was" ); |
174 | is( -x $copy, -x $orig, " executable if original was" ); |
a7d1454b |
175 | } |
176 | rmtree('copy'); |
177 | |
178 | |
0300da75 |
179 | # poison the manifest, and add a comment that should be reported |
180 | add_file( 'MANIFEST', 'none #none' ); |
f6d6199c |
181 | is( ExtUtils::Manifest::maniread()->{none}, '#none', |
182 | 'maniread found comment' ); |
0300da75 |
183 | |
184 | ok( mkdir( 'copy', 0777 ), 'made copy directory' ); |
0300da75 |
185 | $files = maniread(); |
186 | eval { (undef, $warn) = catch_warning( sub { |
b3217f3b |
187 | manicopy( $files, 'copy', 'cp' ) }) |
0300da75 |
188 | }; |
189 | |
190 | # a newline comes through, so get rid of it |
191 | chomp($warn); |
6dbcfe36 |
192 | # the copy should have given a warning |
193 | like($warn, qr/^none not found/, 'carped about none' ); |
194 | ($res, $warn) = catch_warning( \&skipcheck ); |
f6d6199c |
195 | like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' ); |
0300da75 |
196 | |
197 | # tell ExtUtils::Manifest to use a different file |
f6d6199c |
198 | { |
199 | local $ExtUtils::Manifest::MANIFEST = 'albatross'; |
200 | ($res, $warn) = catch_warning( \&mkmanifest ); |
201 | like( $warn, qr/Added to albatross: /, 'using a new manifest file' ); |
b3217f3b |
202 | |
f6d6199c |
203 | # add the new file to the list of files to be deleted |
2530b651 |
204 | $Files{'albatross'}++; |
39234879 |
205 | } |
0300da75 |
206 | |
0300da75 |
207 | |
f6d6199c |
208 | # Make sure MANIFEST.SKIP is using complete relative paths |
209 | add_file( 'MANIFEST.SKIP' => "^moretest/q\n" ); |
210 | |
211 | # This'll skip moretest/quux |
212 | ($res, $warn) = catch_warning( \&skipcheck ); |
45bc4d3a |
213 | like( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' ); |
214 | |
215 | |
216 | # There was a bug where entries in MANIFEST would be blotted out |
217 | # by MANIFEST.SKIP rules. |
218 | add_file( 'MANIFEST.SKIP' => 'foo' ); |
479d2113 |
219 | add_file( 'MANIFEST' => "foobar\n" ); |
45bc4d3a |
220 | add_file( 'foobar' => '123' ); |
221 | ($res, $warn) = catch_warning( \&manicheck ); |
4c857482 |
222 | is( $res, '', 'MANIFEST overrides MANIFEST.SKIP' ); |
b3217f3b |
223 | is( $warn, '', 'MANIFEST overrides MANIFEST.SKIP, no warnings' ); |
f6d6199c |
224 | |
479d2113 |
225 | $files = maniread; |
226 | ok( !$files->{wibble}, 'MANIFEST in good state' ); |
227 | maniadd({ wibble => undef }); |
228 | maniadd({ yarrow => "hock" }); |
229 | $files = maniread; |
230 | is( $files->{wibble}, '', 'maniadd() with undef comment' ); |
231 | is( $files->{yarrow}, 'hock',' with comment' ); |
232 | is( $files->{foobar}, '', ' preserved old entries' ); |
5ca25ae7 |
233 | |
6dbcfe36 |
234 | my %funky_files; |
235 | # test including a filename with a space |
236 | SKIP: { |
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'; |
248 | } |
249 | |
250 | # test including a filename with a space and a quote |
251 | SKIP: { |
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'; |
259 | } |
260 | |
261 | # test including a filename with a space and a backslash |
262 | SKIP: { |
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'; |
270 | } |
271 | |
272 | # test including a filename with a space, quote, and a backslash |
273 | SKIP: { |
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'; |
281 | } |
282 | |
283 | my @funky_keys = qw(space space_quote space_backslash space_quote_backslash); |
1c14aae0 |
284 | # test including an external manifest.skip file in MANIFEST.SKIP |
285 | { |
286 | maniadd({ foo => undef , albatross => undef, |
287 | 'mymanifest.skip' => undef, 'mydefault.skip' => undef}); |
6dbcfe36 |
288 | for (@funky_keys) { |
289 | maniadd( {$funky_files{$_} => $_} ) if defined $funky_files{$_}; |
290 | } |
291 | |
1c14aae0 |
292 | add_file('mymanifest.skip' => "^foo\n"); |
293 | add_file('mydefault.skip' => "^my\n"); |
6dbcfe36 |
294 | local $ExtUtils::Manifest::DEFAULT_MSKIP = |
1c14aae0 |
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/, |
302 | "Skipping $_" ); |
303 | } |
6dbcfe36 |
304 | for my $funky_key (@funky_keys) { |
305 | SKIP: { |
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"); |
310 | } |
311 | } |
1c14aae0 |
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" ); |
316 | } |
6dbcfe36 |
317 | for my $funky_key (@funky_keys) { |
318 | SKIP: { |
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"); |
323 | } |
324 | } |
1c14aae0 |
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' ); |
6dbcfe36 |
335 | |
336 | # test exclusion of funky files |
337 | for my $funky_key (@funky_keys) { |
338 | SKIP: { |
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" ); |
343 | } |
344 | } |
345 | |
346 | # tests for maniskip |
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' ); |
372 | |
7e4d7138 |
373 | my $extsep = $Is_VMS_noefs ? '_' : '.'; |
a2fa79ff |
374 | $Files{"$_.bak"}++ for ('MANIFEST', "MANIFEST${extsep}SKIP"); |
1c14aae0 |
375 | } |
376 | |
2530b651 |
377 | add_file('MANIFEST' => 'Makefile.PL'); |
9d058bf8 |
378 | maniadd({ foo => 'bar' }); |
2530b651 |
379 | $files = maniread; |
380 | # VMS downcases the MANIFEST. We normalize it here to match. |
381 | %$files = map { (lc $_ => $files->{$_}) } keys %$files; |
382 | my %expect = ( 'makefile.pl' => '', |
5ca25ae7 |
383 | 'foo' => 'bar' |
384 | ); |
2530b651 |
385 | is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline'); |
0300da75 |
386 | |
1c14aae0 |
387 | #add_file('MANIFEST' => 'Makefile.PL'); |
388 | #maniadd({ foo => 'bar' }); |
5ca25ae7 |
389 | |
2c91f887 |
390 | SKIP: { |
391 | chmod( 0400, 'MANIFEST' ); |
392 | skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST'; |
393 | |
380d5532 |
394 | eval { |
395 | maniadd({ 'foo' => 'bar' }); |
396 | }; |
2c91f887 |
397 | is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" ); |
398 | |
399 | eval { |
400 | maniadd({ 'grrrwoof' => 'yippie' }); |
401 | }; |
30361541 |
402 | like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/, |
2c91f887 |
403 | "maniadd() dies if it can't open the MANIFEST" ); |
404 | |
0aa703b2 |
405 | chmod( 0600, 'MANIFEST' ); |
2c91f887 |
406 | } |
a7d1454b |
407 | |
2c91f887 |
408 | |
0300da75 |
409 | END { |
2530b651 |
410 | is( unlink( keys %Files ), keys %Files, 'remove all added files' ); |
0300da75 |
411 | remove_dir( 'moretest', 'copy' ); |
412 | |
413 | # now get rid of the parent directory |
414 | ok( chdir( $cwd ), 'return to parent directory' ); |
415 | remove_dir( 'mantest' ); |
416 | } |
349e1be1 |
417 | |