4 if( $ENV{PERL_CORE} ) {
6 unshift @INC, '../lib';
16 # these files help the test run
17 use Test::More tests => 41;
20 # these files are needed for the module itself
24 # We're going to be chdir'ing and modules are sometimes loaded on the
25 # fly in this test, so we need an absolute @INC.
26 @INC = map { File::Spec->rel2abs($_) } @INC;
28 # keep track of everything added so it can all be deleted
31 my ($file, $data) = @_;
33 1 while unlink $file; # or else we'll get multiple versions on VMS
34 open( T, '>'.$file) or return;
41 open( M, 'MANIFEST' ) or return;
42 chomp( my @files = <M> );
49 local $SIG{__WARN__} = sub { $warn .= $_[0] };
50 return join('', $_[0]->() ), $warn;
54 ok( rmdir( $_ ), "remove $_ directory" ) for @_;
57 # use module, import functions
59 use_ok( 'ExtUtils::Manifest',
60 qw( mkmanifest manicheck filecheck fullcheck
61 maniread manicopy skipcheck maniadd) );
64 my $cwd = Cwd::getcwd();
66 # Just in case any old files were lying around.
69 ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
70 ok( chdir( 'mantest' ), 'chdir() to mantest' );
71 ok( add_file('foo'), 'add a temporary file' );
73 # there shouldn't be a MANIFEST there
74 my ($res, $warn) = catch_warning( \&mkmanifest );
76 $warn = join("", map { "$_|" }
77 sort { lc($a) cmp lc($b) } split /\r?\n/, $warn);
78 is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
79 "mkmanifest() displayed its additions" );
82 ok( -e 'MANIFEST', 'create MANIFEST file' );
84 my @list = read_manifest();
85 is( @list, 2, 'check files in MANIFEST' );
86 ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
88 # after adding bar, the MANIFEST is out of date
89 ok( add_file( 'bar' ), 'add another file' );
90 ok( ! manicheck(), 'MANIFEST now out of sync' );
92 # it reports that bar has been added and throws a warning
93 ($res, $warn) = catch_warning( \&filecheck );
95 like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
96 is( $res, 'bar', 'bar reported as new' );
98 # now quiet the warning that bar was added and test again
99 ($res, $warn) = do { local $ExtUtils::Manifest::Quiet = 1;
100 catch_warning( \&skipcheck )
102 cmp_ok( $warn, 'eq', '', 'disabled warnings' );
104 # add a skip file with a rule to skip itself (and the nonexistent glob '*baz*')
105 add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
107 # this'll skip the new file
108 ($res, $warn) = catch_warning( \&skipcheck );
109 like( $warn, qr/^Skipping MANIFEST\.SKIP/i, 'got skipping warning' );
113 @skipped = skipcheck()
116 is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' );
119 local $ExtUtils::Manifest::Quiet = 1;
120 is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
123 # add a subdirectory and a file there that should be found
124 ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
125 add_file( File::Spec->catfile('moretest', 'quux'), 'quux' );
126 ok( exists( ExtUtils::Manifest::manifind()->{'moretest/quux'} ),
127 "manifind found moretest/quux" );
129 # only MANIFEST and foo are in the manifest
131 my $files = maniread();
132 is( keys %$files, 2, 'two files found' );
133 is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST',
134 'both files found' );
135 is( $_, 'foo', q{maniread() doesn't clobber $_} );
137 # poison the manifest, and add a comment that should be reported
138 add_file( 'MANIFEST', 'none #none' );
139 is( ExtUtils::Manifest::maniread()->{none}, '#none',
140 'maniread found comment' );
142 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
145 eval { (undef, $warn) = catch_warning( sub {
146 manicopy( $files, 'copy', 'cp' ) })
148 like( $@, qr/^Can't read none: /, 'croaked about none' );
150 # a newline comes through, so get rid of it
153 # the copy should have given one warning and one error
154 like($warn, qr/^Skipping MANIFEST.SKIP/i, 'warned about MANIFEST.SKIP' );
156 # tell ExtUtils::Manifest to use a different file
158 local $ExtUtils::Manifest::MANIFEST = 'albatross';
159 ($res, $warn) = catch_warning( \&mkmanifest );
160 like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
162 # add the new file to the list of files to be deleted
163 $Files{'albatross'}++;
167 # Make sure MANIFEST.SKIP is using complete relative paths
168 add_file( 'MANIFEST.SKIP' => "^moretest/q\n" );
170 # This'll skip moretest/quux
171 ($res, $warn) = catch_warning( \&skipcheck );
172 like( $warn, qr{^Skipping moretest/quux$}i, 'got skipping warning again' );
175 # There was a bug where entries in MANIFEST would be blotted out
176 # by MANIFEST.SKIP rules.
177 add_file( 'MANIFEST.SKIP' => 'foo' );
178 add_file( 'MANIFEST' => "foobar\n" );
179 add_file( 'foobar' => '123' );
180 ($res, $warn) = catch_warning( \&manicheck );
181 is( $res, '', 'MANIFEST overrides MANIFEST.SKIP' );
182 is( $warn, undef, 'MANIFEST overrides MANIFEST.SKIP, no warnings' );
185 ok( !$files->{wibble}, 'MANIFEST in good state' );
186 maniadd({ wibble => undef });
187 maniadd({ yarrow => "hock" });
189 is( $files->{wibble}, '', 'maniadd() with undef comment' );
190 is( $files->{yarrow}, 'hock',' with comment' );
191 is( $files->{foobar}, '', ' preserved old entries' );
193 add_file('MANIFEST' => 'Makefile.PL');
194 maniadd({ 'META.yml' => 'Module meta-data (added by MakeMaker)' });
196 # VMS downcases the MANIFEST. We normalize it here to match.
197 %$files = map { (lc $_ => $files->{$_}) } keys %$files;
198 my %expect = ( 'makefile.pl' => '',
199 'meta.yml' => 'Module meta-data (added by MakeMaker)'
201 is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline');
204 chmod( 0400, 'MANIFEST' );
205 skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST';
207 if ( $^O eq 'VMS' ) {
209 maniadd({ 'meta.yml' => 'hock' });
214 maniadd({ 'META.yml' => 'hock' });
217 is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" );
220 maniadd({ 'grrrwoof' => 'yippie' });
222 like( $@, qr/^Could not open MANIFEST/,
223 "maniadd() dies if it can't open the MANIFEST" );
229 is( unlink( keys %Files ), keys %Files, 'remove all added files' );
230 remove_dir( 'moretest', 'copy' );
232 # now get rid of the parent directory
233 ok( chdir( $cwd ), 'return to parent directory' );
234 unlink('mantest/MANIFEST');
235 remove_dir( 'mantest' );