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 | |
1c14aae0 |
16 | use Test::More tests => 66; |
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 |
479d2113 |
36 | open( T, '>'.$file) or return; |
37 | print T $data; |
2530b651 |
38 | ++$Files{$file}; |
57b1a898 |
39 | close T; |
0300da75 |
40 | } |
41 | |
42 | sub read_manifest { |
a7d1454b |
43 | open( M, 'MANIFEST' ) or return; |
44 | chomp( my @files = <M> ); |
57b1a898 |
45 | close M; |
a7d1454b |
46 | return @files; |
0300da75 |
47 | } |
48 | |
49 | sub catch_warning { |
b3217f3b |
50 | my $warn = ''; |
a7d1454b |
51 | local $SIG{__WARN__} = sub { $warn .= $_[0] }; |
52 | return join('', $_[0]->() ), $warn; |
0300da75 |
53 | } |
54 | |
55 | sub remove_dir { |
a7d1454b |
56 | ok( rmdir( $_ ), "remove $_ directory" ) for @_; |
0300da75 |
57 | } |
58 | |
59 | # use module, import functions |
f6d6199c |
60 | BEGIN { |
61 | use_ok( 'ExtUtils::Manifest', |
62 | qw( mkmanifest manicheck filecheck fullcheck |
479d2113 |
63 | maniread manicopy skipcheck maniadd) ); |
f6d6199c |
64 | } |
0300da75 |
65 | |
66 | my $cwd = Cwd::getcwd(); |
67 | |
68 | # Just in case any old files were lying around. |
69 | rmtree('mantest'); |
70 | |
71 | ok( mkdir( 'mantest', 0777 ), 'make mantest directory' ); |
72 | ok( chdir( 'mantest' ), 'chdir() to mantest' ); |
73 | ok( add_file('foo'), 'add a temporary file' ); |
74 | |
1c14aae0 |
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'}; |
80 | |
0300da75 |
81 | # there shouldn't be a MANIFEST there |
b3217f3b |
82 | my ($res, $warn) = catch_warning( \&mkmanifest ); |
f2e6bef3 |
83 | # Canonize the order. |
f6d6199c |
84 | $warn = join("", map { "$_|" } |
85 | sort { lc($a) cmp lc($b) } split /\r?\n/, $warn); |
f2e6bef3 |
86 | is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|", |
f6d6199c |
87 | "mkmanifest() displayed its additions" ); |
0300da75 |
88 | |
89 | # and now you see it |
90 | ok( -e 'MANIFEST', 'create MANIFEST file' ); |
91 | |
92 | my @list = read_manifest(); |
93 | is( @list, 2, 'check files in MANIFEST' ); |
94 | ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' ); |
95 | |
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' ); |
99 | |
100 | # it reports that bar has been added and throws a warning |
101 | ($res, $warn) = catch_warning( \&filecheck ); |
102 | |
103 | like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' ); |
104 | is( $res, 'bar', 'bar reported as new' ); |
105 | |
106 | # now quiet the warning that bar was added and test again |
b3217f3b |
107 | ($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1; |
108 | catch_warning( \&skipcheck ) |
f6d6199c |
109 | }; |
b3217f3b |
110 | is( $warn, '', 'disabled warnings' ); |
0300da75 |
111 | |
f6d6199c |
112 | # add a skip file with a rule to skip itself (and the nonexistent glob '*baz*') |
0300da75 |
113 | add_file( 'MANIFEST.SKIP', "baz\n.SKIP" ); |
114 | |
115 | # this'll skip the new file |
f6d6199c |
116 | ($res, $warn) = catch_warning( \&skipcheck ); |
117 | like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' ); |
0300da75 |
118 | |
45bc4d3a |
119 | my @skipped; |
0300da75 |
120 | catch_warning( sub { |
4c857482 |
121 | @skipped = skipcheck() |
0300da75 |
122 | }); |
123 | |
45bc4d3a |
124 | is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' ); |
0300da75 |
125 | |
f6d6199c |
126 | { |
127 | local $ExtUtils::Manifest::Quiet = 1; |
128 | is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' ); |
129 | } |
0300da75 |
130 | |
131 | # add a subdirectory and a file there that should be found |
132 | ok( mkdir( 'moretest', 0777 ), 'created moretest directory' ); |
f6d6199c |
133 | add_file( File::Spec->catfile('moretest', 'quux'), 'quux' ); |
134 | ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ), |
135 | "manifind found moretest/quux" ); |
0300da75 |
136 | |
137 | # only MANIFEST and foo are in the manifest |
2530b651 |
138 | $_ = 'foo'; |
0300da75 |
139 | my $files = maniread(); |
140 | is( keys %$files, 2, 'two files found' ); |
f6d6199c |
141 | is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST', |
142 | 'both files found' ); |
2530b651 |
143 | is( $_, 'foo', q{maniread() doesn't clobber $_} ); |
0300da75 |
144 | |
a7d1454b |
145 | ok( mkdir( 'copy', 0777 ), 'made copy directory' ); |
146 | |
147 | # Check that manicopy copies files. |
148 | manicopy( $files, 'copy', 'cp' ); |
149 | my @copies = (); |
150 | find( sub { push @copies, $_ if -f }, 'copy' ); |
151 | @copies = map { s/\.$//; $_ } @copies if $Is_VMS; # VMS likes to put dots on |
152 | # the end of files. |
153 | # Have to compare insensitively for non-case preserving VMS |
154 | is_deeply( [sort map { lc } @copies], [sort map { lc } keys %$files] ); |
155 | |
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" ); |
4c857482 |
160 | is( -w $copy, -w $orig, " writable if original was" ); |
161 | is( -x $copy, -x $orig, " executable if original was" ); |
a7d1454b |
162 | } |
163 | rmtree('copy'); |
164 | |
165 | |
0300da75 |
166 | # poison the manifest, and add a comment that should be reported |
167 | add_file( 'MANIFEST', 'none #none' ); |
f6d6199c |
168 | is( ExtUtils::Manifest::maniread()->{none}, '#none', |
169 | 'maniread found comment' ); |
0300da75 |
170 | |
171 | ok( mkdir( 'copy', 0777 ), 'made copy directory' ); |
0300da75 |
172 | $files = maniread(); |
173 | eval { (undef, $warn) = catch_warning( sub { |
b3217f3b |
174 | manicopy( $files, 'copy', 'cp' ) }) |
0300da75 |
175 | }; |
57b1a898 |
176 | like( $@, qr/^Can't read none: /, 'croaked about none' ); |
0300da75 |
177 | |
178 | # a newline comes through, so get rid of it |
179 | chomp($warn); |
180 | |
181 | # the copy should have given one warning and one error |
f6d6199c |
182 | like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' ); |
0300da75 |
183 | |
184 | # tell ExtUtils::Manifest to use a different file |
f6d6199c |
185 | { |
186 | local $ExtUtils::Manifest::MANIFEST = 'albatross'; |
187 | ($res, $warn) = catch_warning( \&mkmanifest ); |
188 | like( $warn, qr/Added to albatross: /, 'using a new manifest file' ); |
b3217f3b |
189 | |
f6d6199c |
190 | # add the new file to the list of files to be deleted |
2530b651 |
191 | $Files{'albatross'}++; |
39234879 |
192 | } |
0300da75 |
193 | |
0300da75 |
194 | |
f6d6199c |
195 | # Make sure MANIFEST.SKIP is using complete relative paths |
196 | add_file( 'MANIFEST.SKIP' => "^moretest/q\n" ); |
197 | |
198 | # This'll skip moretest/quux |
199 | ($res, $warn) = catch_warning( \&skipcheck ); |
45bc4d3a |
200 | like( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' ); |
201 | |
202 | |
203 | # There was a bug where entries in MANIFEST would be blotted out |
204 | # by MANIFEST.SKIP rules. |
205 | add_file( 'MANIFEST.SKIP' => 'foo' ); |
479d2113 |
206 | add_file( 'MANIFEST' => "foobar\n" ); |
45bc4d3a |
207 | add_file( 'foobar' => '123' ); |
208 | ($res, $warn) = catch_warning( \&manicheck ); |
4c857482 |
209 | is( $res, '', 'MANIFEST overrides MANIFEST.SKIP' ); |
b3217f3b |
210 | is( $warn, '', 'MANIFEST overrides MANIFEST.SKIP, no warnings' ); |
f6d6199c |
211 | |
479d2113 |
212 | $files = maniread; |
213 | ok( !$files->{wibble}, 'MANIFEST in good state' ); |
214 | maniadd({ wibble => undef }); |
215 | maniadd({ yarrow => "hock" }); |
216 | $files = maniread; |
217 | is( $files->{wibble}, '', 'maniadd() with undef comment' ); |
218 | is( $files->{yarrow}, 'hock',' with comment' ); |
219 | is( $files->{foobar}, '', ' preserved old entries' ); |
5ca25ae7 |
220 | |
1c14aae0 |
221 | # test including an external manifest.skip file in MANIFEST.SKIP |
222 | { |
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/, |
235 | "Skipping $_" ); |
236 | } |
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" ); |
241 | } |
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' ); |
a2fa79ff |
252 | my $extsep = $Is_VMS ? '_' : '.'; |
253 | $Files{"$_.bak"}++ for ('MANIFEST', "MANIFEST${extsep}SKIP"); |
1c14aae0 |
254 | } |
255 | |
2530b651 |
256 | add_file('MANIFEST' => 'Makefile.PL'); |
9d058bf8 |
257 | maniadd({ foo => 'bar' }); |
2530b651 |
258 | $files = maniread; |
259 | # VMS downcases the MANIFEST. We normalize it here to match. |
260 | %$files = map { (lc $_ => $files->{$_}) } keys %$files; |
261 | my %expect = ( 'makefile.pl' => '', |
5ca25ae7 |
262 | 'foo' => 'bar' |
263 | ); |
2530b651 |
264 | is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline'); |
0300da75 |
265 | |
1c14aae0 |
266 | #add_file('MANIFEST' => 'Makefile.PL'); |
267 | #maniadd({ foo => 'bar' }); |
5ca25ae7 |
268 | |
2c91f887 |
269 | SKIP: { |
270 | chmod( 0400, 'MANIFEST' ); |
271 | skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST'; |
272 | |
380d5532 |
273 | eval { |
274 | maniadd({ 'foo' => 'bar' }); |
275 | }; |
2c91f887 |
276 | is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" ); |
277 | |
278 | eval { |
279 | maniadd({ 'grrrwoof' => 'yippie' }); |
280 | }; |
30361541 |
281 | like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/, |
2c91f887 |
282 | "maniadd() dies if it can't open the MANIFEST" ); |
283 | |
0aa703b2 |
284 | chmod( 0600, 'MANIFEST' ); |
2c91f887 |
285 | } |
a7d1454b |
286 | |
2c91f887 |
287 | |
0300da75 |
288 | END { |
2530b651 |
289 | is( unlink( keys %Files ), keys %Files, 'remove all added files' ); |
0300da75 |
290 | remove_dir( 'moretest', 'copy' ); |
291 | |
292 | # now get rid of the parent directory |
293 | ok( chdir( $cwd ), 'return to parent directory' ); |
294 | remove_dir( 'mantest' ); |
295 | } |
349e1be1 |
296 | |