4 if( $ENV{PERL_CORE} ) {
6 unshift @INC, '../lib';
16 use Test::More tests => 49;
23 my $Is_VMS = $^O eq 'VMS';
25 # We're going to be chdir'ing and modules are sometimes loaded on the
26 # fly in this test, so we need an absolute @INC.
27 @INC = map { File::Spec->rel2abs($_) } @INC;
29 # keep track of everything added so it can all be deleted
32 my ($file, $data) = @_;
34 1 while unlink $file; # or else we'll get multiple versions on VMS
35 open( T, '>'.$file) or return;
42 open( M, 'MANIFEST' ) or return;
43 chomp( my @files = <M> );
50 local $SIG{__WARN__} = sub { $warn .= $_[0] };
51 return join('', $_[0]->() ), $warn;
55 ok( rmdir( $_ ), "remove $_ directory" ) for @_;
58 # use module, import functions
60 use_ok( 'ExtUtils::Manifest',
61 qw( mkmanifest manicheck filecheck fullcheck
62 maniread manicopy skipcheck maniadd) );
65 my $cwd = Cwd::getcwd();
67 # Just in case any old files were lying around.
70 ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
71 ok( chdir( 'mantest' ), 'chdir() to mantest' );
72 ok( add_file('foo'), 'add a temporary file' );
74 # there shouldn't be a MANIFEST there
75 my ($res, $warn) = catch_warning( \&mkmanifest );
77 $warn = join("", map { "$_|" }
78 sort { lc($a) cmp lc($b) } split /\r?\n/, $warn);
79 is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
80 "mkmanifest() displayed its additions" );
83 ok( -e 'MANIFEST', 'create MANIFEST file' );
85 my @list = read_manifest();
86 is( @list, 2, 'check files in MANIFEST' );
87 ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
89 # after adding bar, the MANIFEST is out of date
90 ok( add_file( 'bar' ), 'add another file' );
91 ok( ! manicheck(), 'MANIFEST now out of sync' );
93 # it reports that bar has been added and throws a warning
94 ($res, $warn) = catch_warning( \&filecheck );
96 like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
97 is( $res, 'bar', 'bar reported as new' );
99 # now quiet the warning that bar was added and test again
100 ($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1;
101 catch_warning( \&skipcheck )
103 cmp_ok( $warn, 'eq', '', 'disabled warnings' );
105 # add a skip file with a rule to skip itself (and the nonexistent glob '*baz*')
106 add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
108 # this'll skip the new file
109 ($res, $warn) = catch_warning( \&skipcheck );
110 like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' );
114 @skipped = skipcheck()
117 is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' );
120 local $ExtUtils::Manifest::Quiet = 1;
121 is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
124 # add a subdirectory and a file there that should be found
125 ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
126 add_file( File::Spec->catfile('moretest', 'quux'), 'quux' );
127 ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ),
128 "manifind found moretest/quux" );
130 # only MANIFEST and foo are in the manifest
132 my $files = maniread();
133 is( keys %$files, 2, 'two files found' );
134 is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST',
135 'both files found' );
136 is( $_, 'foo', q{maniread() doesn't clobber $_} );
138 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
140 # Check that manicopy copies files.
141 manicopy( $files, 'copy', 'cp' );
143 find( sub { push @copies, $_ if -f }, 'copy' );
144 @copies = map { s/\.$//; $_ } @copies if $Is_VMS; # VMS likes to put dots on
146 # Have to compare insensitively for non-case preserving VMS
147 is_deeply( [sort map { lc } @copies], [sort map { lc } keys %$files] );
149 # cp would leave files readonly, so check permissions.
150 foreach my $orig (@copies) {
151 my $copy = "copy/$orig";
152 ok( -r $copy, "$copy: must be readable" );
153 is( -w $copy, -w $orig, " writable if original was" );
154 is( -x $copy, -x $orig, " executable if original was" );
159 # poison the manifest, and add a comment that should be reported
160 add_file( 'MANIFEST', 'none #none' );
161 is( ExtUtils::Manifest::maniread()->{none}, '#none',
162 'maniread found comment' );
164 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
166 eval { (undef, $warn) = catch_warning( sub {
167 manicopy( $files, 'copy', 'cp' ) })
169 like( $@, qr/^Can't read none: /, 'croaked about none' );
171 # a newline comes through, so get rid of it
174 # the copy should have given one warning and one error
175 like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' );
177 # tell ExtUtils::Manifest to use a different file
179 local $ExtUtils::Manifest::MANIFEST = 'albatross';
180 ($res, $warn) = catch_warning( \&mkmanifest );
181 like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
183 # add the new file to the list of files to be deleted
184 $Files{'albatross'}++;
188 # Make sure MANIFEST.SKIP is using complete relative paths
189 add_file( 'MANIFEST.SKIP' => "^moretest/q\n" );
191 # This'll skip moretest/quux
192 ($res, $warn) = catch_warning( \&skipcheck );
193 like( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' );
196 # There was a bug where entries in MANIFEST would be blotted out
197 # by MANIFEST.SKIP rules.
198 add_file( 'MANIFEST.SKIP' => 'foo' );
199 add_file( 'MANIFEST' => "foobar\n" );
200 add_file( 'foobar' => '123' );
201 ($res, $warn) = catch_warning( \&manicheck );
202 is( $res, '', 'MANIFEST overrides MANIFEST.SKIP' );
203 is( $warn, undef, 'MANIFEST overrides MANIFEST.SKIP, no warnings' );
206 ok( !$files->{wibble}, 'MANIFEST in good state' );
207 maniadd({ wibble => undef });
208 maniadd({ yarrow => "hock" });
210 is( $files->{wibble}, '', 'maniadd() with undef comment' );
211 is( $files->{yarrow}, 'hock',' with comment' );
212 is( $files->{foobar}, '', ' preserved old entries' );
214 add_file('MANIFEST' => 'Makefile.PL');
215 maniadd({ foo => 'bar' });
217 # VMS downcases the MANIFEST. We normalize it here to match.
218 %$files = map { (lc $_ => $files->{$_}) } keys %$files;
219 my %expect = ( 'makefile.pl' => '',
222 is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline');
224 add_file('MANIFEST' => 'Makefile.PL');
225 maniadd({ foo => 'bar' });
228 chmod( 0400, 'MANIFEST' );
229 skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST';
232 maniadd({ 'foo' => 'bar' });
234 is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" );
237 maniadd({ 'grrrwoof' => 'yippie' });
239 like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/,
240 "maniadd() dies if it can't open the MANIFEST" );
242 chmod( 0600, 'MANIFEST' );
247 is( unlink( keys %Files ), keys %Files, 'remove all added files' );
248 remove_dir( 'moretest', 'copy' );
250 # now get rid of the parent directory
251 ok( chdir( $cwd ), 'return to parent directory' );
252 remove_dir( 'mantest' );