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'; |
57b1a898 |
25 | |
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; |
0300da75 |
29 | |
30 | # keep track of everything added so it can all be deleted |
2530b651 |
31 | my %Files; |
0300da75 |
32 | sub add_file { |
479d2113 |
33 | my ($file, $data) = @_; |
34 | $data ||= 'foo'; |
2530b651 |
35 | 1 while unlink $file; # or else we'll get multiple versions on VMS |
6dbcfe36 |
36 | open( T, '> '.$file) or return; |
479d2113 |
37 | print T $data; |
57b1a898 |
38 | close T; |
7a5ea4ae |
39 | return 0 unless -e $file; # exists under the name we gave it ? |
40 | ++$Files{$file}; |
0300da75 |
41 | } |
42 | |
43 | sub read_manifest { |
a7d1454b |
44 | open( M, 'MANIFEST' ) or return; |
45 | chomp( my @files = <M> ); |
57b1a898 |
46 | close M; |
a7d1454b |
47 | return @files; |
0300da75 |
48 | } |
49 | |
50 | sub catch_warning { |
b3217f3b |
51 | my $warn = ''; |
a7d1454b |
52 | local $SIG{__WARN__} = sub { $warn .= $_[0] }; |
53 | return join('', $_[0]->() ), $warn; |
0300da75 |
54 | } |
55 | |
56 | sub remove_dir { |
a7d1454b |
57 | ok( rmdir( $_ ), "remove $_ directory" ) for @_; |
0300da75 |
58 | } |
59 | |
60 | # use module, import functions |
f6d6199c |
61 | BEGIN { |
62 | use_ok( 'ExtUtils::Manifest', |
63 | qw( mkmanifest manicheck filecheck fullcheck |
6dbcfe36 |
64 | maniread manicopy skipcheck maniadd maniskip) ); |
f6d6199c |
65 | } |
0300da75 |
66 | |
67 | my $cwd = Cwd::getcwd(); |
68 | |
69 | # Just in case any old files were lying around. |
70 | rmtree('mantest'); |
71 | |
72 | ok( mkdir( 'mantest', 0777 ), 'make mantest directory' ); |
73 | ok( chdir( 'mantest' ), 'chdir() to mantest' ); |
74 | ok( add_file('foo'), 'add a temporary file' ); |
75 | |
1c14aae0 |
76 | # This ensures the -x check for manicopy means something |
77 | # Some platforms don't have chmod or an executable bit, in which case |
78 | # this call will do nothing or fail, but on the platforms where chmod() |
79 | # works, we test the executable bit is copied |
80 | chmod( 0744, 'foo') if $Config{'chmod'}; |
81 | |
0300da75 |
82 | # there shouldn't be a MANIFEST there |
b3217f3b |
83 | my ($res, $warn) = catch_warning( \&mkmanifest ); |
f2e6bef3 |
84 | # Canonize the order. |
f6d6199c |
85 | $warn = join("", map { "$_|" } |
86 | sort { lc($a) cmp lc($b) } split /\r?\n/, $warn); |
f2e6bef3 |
87 | is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|", |
f6d6199c |
88 | "mkmanifest() displayed its additions" ); |
0300da75 |
89 | |
90 | # and now you see it |
91 | ok( -e 'MANIFEST', 'create MANIFEST file' ); |
92 | |
93 | my @list = read_manifest(); |
94 | is( @list, 2, 'check files in MANIFEST' ); |
95 | ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' ); |
96 | |
97 | # after adding bar, the MANIFEST is out of date |
98 | ok( add_file( 'bar' ), 'add another file' ); |
99 | ok( ! manicheck(), 'MANIFEST now out of sync' ); |
100 | |
101 | # it reports that bar has been added and throws a warning |
102 | ($res, $warn) = catch_warning( \&filecheck ); |
103 | |
104 | like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' ); |
105 | is( $res, 'bar', 'bar reported as new' ); |
106 | |
107 | # now quiet the warning that bar was added and test again |
b3217f3b |
108 | ($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1; |
109 | catch_warning( \&skipcheck ) |
f6d6199c |
110 | }; |
b3217f3b |
111 | is( $warn, '', 'disabled warnings' ); |
0300da75 |
112 | |
f6d6199c |
113 | # add a skip file with a rule to skip itself (and the nonexistent glob '*baz*') |
0300da75 |
114 | add_file( 'MANIFEST.SKIP', "baz\n.SKIP" ); |
115 | |
116 | # this'll skip the new file |
f6d6199c |
117 | ($res, $warn) = catch_warning( \&skipcheck ); |
118 | like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' ); |
0300da75 |
119 | |
45bc4d3a |
120 | my @skipped; |
0300da75 |
121 | catch_warning( sub { |
4c857482 |
122 | @skipped = skipcheck() |
0300da75 |
123 | }); |
124 | |
45bc4d3a |
125 | is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' ); |
0300da75 |
126 | |
f6d6199c |
127 | { |
128 | local $ExtUtils::Manifest::Quiet = 1; |
129 | is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' ); |
130 | } |
0300da75 |
131 | |
132 | # add a subdirectory and a file there that should be found |
133 | ok( mkdir( 'moretest', 0777 ), 'created moretest directory' ); |
f6d6199c |
134 | add_file( File::Spec->catfile('moretest', 'quux'), 'quux' ); |
135 | ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ), |
136 | "manifind found moretest/quux" ); |
0300da75 |
137 | |
138 | # only MANIFEST and foo are in the manifest |
2530b651 |
139 | $_ = 'foo'; |
0300da75 |
140 | my $files = maniread(); |
141 | is( keys %$files, 2, 'two files found' ); |
f6d6199c |
142 | is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST', |
143 | 'both files found' ); |
2530b651 |
144 | is( $_, 'foo', q{maniread() doesn't clobber $_} ); |
0300da75 |
145 | |
a7d1454b |
146 | ok( mkdir( 'copy', 0777 ), 'made copy directory' ); |
147 | |
148 | # Check that manicopy copies files. |
149 | manicopy( $files, 'copy', 'cp' ); |
150 | my @copies = (); |
151 | find( sub { push @copies, $_ if -f }, 'copy' ); |
152 | @copies = map { s/\.$//; $_ } @copies if $Is_VMS; # VMS likes to put dots on |
153 | # the end of files. |
154 | # Have to compare insensitively for non-case preserving VMS |
155 | is_deeply( [sort map { lc } @copies], [sort map { lc } keys %$files] ); |
156 | |
157 | # cp would leave files readonly, so check permissions. |
158 | foreach my $orig (@copies) { |
159 | my $copy = "copy/$orig"; |
160 | ok( -r $copy, "$copy: must be readable" ); |
4c857482 |
161 | is( -w $copy, -w $orig, " writable if original was" ); |
162 | is( -x $copy, -x $orig, " executable if original was" ); |
a7d1454b |
163 | } |
164 | rmtree('copy'); |
165 | |
166 | |
0300da75 |
167 | # poison the manifest, and add a comment that should be reported |
168 | add_file( 'MANIFEST', 'none #none' ); |
f6d6199c |
169 | is( ExtUtils::Manifest::maniread()->{none}, '#none', |
170 | 'maniread found comment' ); |
0300da75 |
171 | |
172 | ok( mkdir( 'copy', 0777 ), 'made copy directory' ); |
0300da75 |
173 | $files = maniread(); |
174 | eval { (undef, $warn) = catch_warning( sub { |
b3217f3b |
175 | manicopy( $files, 'copy', 'cp' ) }) |
0300da75 |
176 | }; |
177 | |
178 | # a newline comes through, so get rid of it |
179 | chomp($warn); |
6dbcfe36 |
180 | # the copy should have given a warning |
181 | like($warn, qr/^none not found/, 'carped about none' ); |
182 | ($res, $warn) = catch_warning( \&skipcheck ); |
f6d6199c |
183 | like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' ); |
0300da75 |
184 | |
185 | # tell ExtUtils::Manifest to use a different file |
f6d6199c |
186 | { |
187 | local $ExtUtils::Manifest::MANIFEST = 'albatross'; |
188 | ($res, $warn) = catch_warning( \&mkmanifest ); |
189 | like( $warn, qr/Added to albatross: /, 'using a new manifest file' ); |
b3217f3b |
190 | |
f6d6199c |
191 | # add the new file to the list of files to be deleted |
2530b651 |
192 | $Files{'albatross'}++; |
39234879 |
193 | } |
0300da75 |
194 | |
0300da75 |
195 | |
f6d6199c |
196 | # Make sure MANIFEST.SKIP is using complete relative paths |
197 | add_file( 'MANIFEST.SKIP' => "^moretest/q\n" ); |
198 | |
199 | # This'll skip moretest/quux |
200 | ($res, $warn) = catch_warning( \&skipcheck ); |
45bc4d3a |
201 | like( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' ); |
202 | |
203 | |
204 | # There was a bug where entries in MANIFEST would be blotted out |
205 | # by MANIFEST.SKIP rules. |
206 | add_file( 'MANIFEST.SKIP' => 'foo' ); |
479d2113 |
207 | add_file( 'MANIFEST' => "foobar\n" ); |
45bc4d3a |
208 | add_file( 'foobar' => '123' ); |
209 | ($res, $warn) = catch_warning( \&manicheck ); |
4c857482 |
210 | is( $res, '', 'MANIFEST overrides MANIFEST.SKIP' ); |
b3217f3b |
211 | is( $warn, '', 'MANIFEST overrides MANIFEST.SKIP, no warnings' ); |
f6d6199c |
212 | |
479d2113 |
213 | $files = maniread; |
214 | ok( !$files->{wibble}, 'MANIFEST in good state' ); |
215 | maniadd({ wibble => undef }); |
216 | maniadd({ yarrow => "hock" }); |
217 | $files = maniread; |
218 | is( $files->{wibble}, '', 'maniadd() with undef comment' ); |
219 | is( $files->{yarrow}, 'hock',' with comment' ); |
220 | is( $files->{foobar}, '', ' preserved old entries' ); |
5ca25ae7 |
221 | |
6dbcfe36 |
222 | my %funky_files; |
223 | # test including a filename with a space |
224 | SKIP: { |
225 | add_file( 'foo bar' => "space" ) |
226 | or skip "couldn't create spaced test file", 2; |
227 | local $ExtUtils::Manifest::MANIFEST = "albatross"; |
228 | maniadd({ 'foo bar' => "contains space"}); |
229 | is( maniread()->{'foo bar'}, "contains space", |
230 | 'spaced manifest filename' ); |
231 | add_file( 'albatross.bak', '' ); |
232 | ($res, $warn) = catch_warning( \&mkmanifest ); |
233 | like( $warn, qr/\A(Added to.*\n)+\z/m, |
234 | 'no warnings about funky filename' ); |
235 | $funky_files{'space'} = 'foo bar'; |
236 | } |
237 | |
238 | # test including a filename with a space and a quote |
239 | SKIP: { |
240 | add_file( 'foo\' baz\'quux' => "quote" ) |
241 | or skip "couldn't create quoted test file", 1; |
242 | local $ExtUtils::Manifest::MANIFEST = "albatross"; |
243 | maniadd({ 'foo\' baz\'quux' => "contains quote"}); |
244 | is( maniread()->{'foo\' baz\'quux'}, "contains quote", |
245 | 'quoted manifest filename' ); |
246 | $funky_files{'space_quote'} = 'foo\' baz\'quux'; |
247 | } |
248 | |
249 | # test including a filename with a space and a backslash |
250 | SKIP: { |
251 | add_file( 'foo bar\\baz' => "backslash" ) |
252 | or skip "couldn't create backslash test file", 1; |
253 | local $ExtUtils::Manifest::MANIFEST = "albatross"; |
254 | maniadd({ 'foo bar\\baz' => "contains backslash"}); |
255 | is( maniread()->{'foo bar\\baz'}, "contains backslash", |
256 | 'backslashed manifest filename' ); |
257 | $funky_files{'space_backslash'} = 'foo bar\\baz'; |
258 | } |
259 | |
260 | # test including a filename with a space, quote, and a backslash |
261 | SKIP: { |
262 | add_file( 'foo bar\\baz\'quux' => "backslash/quote" ) |
263 | or skip "couldn't create backslash/quote test file", 1; |
264 | local $ExtUtils::Manifest::MANIFEST = "albatross"; |
265 | maniadd({ 'foo bar\\baz\'quux' => "backslash and quote"}); |
266 | is( maniread()->{'foo bar\\baz\'quux'}, "backslash and quote", |
267 | 'backslashed and quoted manifest filename' ); |
268 | $funky_files{'space_quote_backslash'} = 'foo bar\\baz\'quux'; |
269 | } |
270 | |
271 | my @funky_keys = qw(space space_quote space_backslash space_quote_backslash); |
1c14aae0 |
272 | # test including an external manifest.skip file in MANIFEST.SKIP |
273 | { |
274 | maniadd({ foo => undef , albatross => undef, |
275 | 'mymanifest.skip' => undef, 'mydefault.skip' => undef}); |
6dbcfe36 |
276 | for (@funky_keys) { |
277 | maniadd( {$funky_files{$_} => $_} ) if defined $funky_files{$_}; |
278 | } |
279 | |
1c14aae0 |
280 | add_file('mymanifest.skip' => "^foo\n"); |
281 | add_file('mydefault.skip' => "^my\n"); |
6dbcfe36 |
282 | local $ExtUtils::Manifest::DEFAULT_MSKIP = |
1c14aae0 |
283 | File::Spec->catfile($cwd, qw(mantest mydefault.skip)); |
284 | my $skip = File::Spec->catfile($cwd, qw(mantest mymanifest.skip)); |
285 | add_file('MANIFEST.SKIP' => |
286 | "albatross\n#!include $skip\n#!include_default"); |
287 | my ($res, $warn) = catch_warning( \&skipcheck ); |
288 | for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) { |
289 | like( $warn, qr/Skipping \b$_\b/, |
290 | "Skipping $_" ); |
291 | } |
6dbcfe36 |
292 | for my $funky_key (@funky_keys) { |
293 | SKIP: { |
294 | my $funky_file = $funky_files{$funky_key}; |
295 | skip "'$funky_key' not created", 1 unless $funky_file; |
296 | like( $warn, qr/Skipping \b\Q$funky_file\E\b/, |
297 | "Skipping $funky_file"); |
298 | } |
299 | } |
1c14aae0 |
300 | ($res, $warn) = catch_warning( \&mkmanifest ); |
301 | for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) { |
302 | like( $warn, qr/Removed from MANIFEST: \b$_\b/, |
303 | "Removed $_ from MANIFEST" ); |
304 | } |
6dbcfe36 |
305 | for my $funky_key (@funky_keys) { |
306 | SKIP: { |
307 | my $funky_file = $funky_files{$funky_key}; |
308 | skip "'$funky_key' not created", 1 unless $funky_file; |
309 | like( $warn, qr/Removed from MANIFEST: \b\Q$funky_file\E\b/, |
310 | "Removed $funky_file from MANIFEST"); |
311 | } |
312 | } |
1c14aae0 |
313 | my $files = maniread; |
314 | ok( ! exists $files->{albatross}, 'albatross excluded via MANIFEST.SKIP' ); |
315 | ok( exists $files->{yarrow}, 'yarrow included in MANIFEST' ); |
316 | ok( exists $files->{bar}, 'bar included in MANIFEST' ); |
317 | ok( ! exists $files->{foobar}, 'foobar excluded via mymanifest.skip' ); |
318 | ok( ! exists $files->{foo}, 'foo excluded via mymanifest.skip' ); |
319 | ok( ! exists $files->{'mymanifest.skip'}, |
320 | 'mymanifest.skip excluded via mydefault.skip' ); |
321 | ok( ! exists $files->{'mydefault.skip'}, |
322 | 'mydefault.skip excluded via mydefault.skip' ); |
6dbcfe36 |
323 | |
324 | # test exclusion of funky files |
325 | for my $funky_key (@funky_keys) { |
326 | SKIP: { |
327 | my $funky_file = $funky_files{$funky_key}; |
328 | skip "'$funky_key' not created", 1 unless $funky_file; |
329 | ok( ! exists $files->{$funky_file}, |
330 | "'$funky_file' excluded via mymanifest.skip" ); |
331 | } |
332 | } |
333 | |
334 | # tests for maniskip |
335 | my $skipchk = maniskip(); |
336 | is ( $skipchk->('albatross'), 1, |
337 | 'albatross excluded via MANIFEST.SKIP' ); |
338 | is( $skipchk->('yarrow'), '', |
339 | 'yarrow included in MANIFEST' ); |
340 | is( $skipchk->('bar'), '', |
341 | 'bar included in MANIFEST' ); |
342 | $skipchk = maniskip('mymanifest.skip'); |
343 | is( $skipchk->('foobar'), 1, |
344 | 'foobar excluded via mymanifest.skip' ); |
345 | is( $skipchk->('foo'), 1, |
346 | 'foo excluded via mymanifest.skip' ); |
347 | is( $skipchk->('mymanifest.skip'), '', |
348 | 'mymanifest.skip included via mydefault.skip' ); |
349 | is( $skipchk->('mydefault.skip'), '', |
350 | 'mydefault.skip included via mydefault.skip' ); |
351 | $skipchk = maniskip('mydefault.skip'); |
352 | is( $skipchk->('foobar'), '', |
353 | 'foobar included via mydefault.skip' ); |
354 | is( $skipchk->('foo'), '', |
355 | 'foo included via mydefault.skip' ); |
356 | is( $skipchk->('mymanifest.skip'), 1, |
357 | 'mymanifest.skip excluded via mydefault.skip' ); |
358 | is( $skipchk->('mydefault.skip'), 1, |
359 | 'mydefault.skip excluded via mydefault.skip' ); |
360 | |
a2fa79ff |
361 | my $extsep = $Is_VMS ? '_' : '.'; |
362 | $Files{"$_.bak"}++ for ('MANIFEST', "MANIFEST${extsep}SKIP"); |
1c14aae0 |
363 | } |
364 | |
2530b651 |
365 | add_file('MANIFEST' => 'Makefile.PL'); |
9d058bf8 |
366 | maniadd({ foo => 'bar' }); |
2530b651 |
367 | $files = maniread; |
368 | # VMS downcases the MANIFEST. We normalize it here to match. |
369 | %$files = map { (lc $_ => $files->{$_}) } keys %$files; |
370 | my %expect = ( 'makefile.pl' => '', |
5ca25ae7 |
371 | 'foo' => 'bar' |
372 | ); |
2530b651 |
373 | is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline'); |
0300da75 |
374 | |
1c14aae0 |
375 | #add_file('MANIFEST' => 'Makefile.PL'); |
376 | #maniadd({ foo => 'bar' }); |
5ca25ae7 |
377 | |
2c91f887 |
378 | SKIP: { |
379 | chmod( 0400, 'MANIFEST' ); |
380 | skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST'; |
381 | |
380d5532 |
382 | eval { |
383 | maniadd({ 'foo' => 'bar' }); |
384 | }; |
2c91f887 |
385 | is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" ); |
386 | |
387 | eval { |
388 | maniadd({ 'grrrwoof' => 'yippie' }); |
389 | }; |
30361541 |
390 | like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/, |
2c91f887 |
391 | "maniadd() dies if it can't open the MANIFEST" ); |
392 | |
0aa703b2 |
393 | chmod( 0600, 'MANIFEST' ); |
2c91f887 |
394 | } |
a7d1454b |
395 | |
2c91f887 |
396 | |
0300da75 |
397 | END { |
2530b651 |
398 | is( unlink( keys %Files ), keys %Files, 'remove all added files' ); |
0300da75 |
399 | remove_dir( 'moretest', 'copy' ); |
400 | |
401 | # now get rid of the parent directory |
402 | ok( chdir( $cwd ), 'return to parent directory' ); |
403 | remove_dir( 'mantest' ); |
404 | } |
349e1be1 |
405 | |