This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Leftovers from Encode 0.99.
[perl5.git] / lib / ExtUtils / t / Manifest.t
CommitLineData
39234879 1#!/usr/bin/perl
0300da75
MS
2
3BEGIN {
39234879
MS
4 if( $ENV{PERL_CORE} ) {
5 chdir 't' if -d 't';
6 unshift @INC, '../lib';
7 }
0300da75 8}
39234879 9chdir 't';
0300da75
MS
10
11# these files help the test run
12use Test::More tests => 31;
13use Cwd;
14
15# these files are needed for the module itself
16use File::Spec;
17use File::Path;
18use Carp::Heavy;
19
20# keep track of everything added so it can all be deleted
21my @files;
22sub add_file {
23 my ($file, $data) = @_;
24 $data ||= 'foo';
020b036f 25 open( my $T, '>', $file) or return;
0300da75
MS
26 print $T $data;
27 push @files, $file;
28}
29
30sub read_manifest {
31 open( my $M, 'MANIFEST' ) or return;
32 chomp( my @files = <$M> );
33 return @files;
34}
35
36sub catch_warning {
37 my $warn;
38 local $SIG{__WARN__} = sub { $warn .= $_[0] };
39 return join('', $_[0]->() ), $warn;
40}
41
42sub remove_dir {
43 ok( rmdir( $_ ), "remove $_ directory" ) for @_;
44}
45
46# use module, import functions
39234879
MS
47BEGIN { use_ok( 'ExtUtils::Manifest',
48 qw( mkmanifest manicheck filecheck fullcheck maniread manicopy) ); }
0300da75
MS
49
50my $cwd = Cwd::getcwd();
51
52# Just in case any old files were lying around.
53rmtree('mantest');
54
55ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
56ok( chdir( 'mantest' ), 'chdir() to mantest' );
57ok( add_file('foo'), 'add a temporary file' );
58
59# there shouldn't be a MANIFEST there
60my ($res, $warn) = catch_warning( \&mkmanifest );
f2e6bef3
JH
61# Canonize the order.
62$warn = join("", map { "$_|" } sort { lc $a cmp lc $b } split /\r?\n/, $warn);
63is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
64 "mkmanifest() displayed it's additions" );
0300da75
MS
65
66# and now you see it
67ok( -e 'MANIFEST', 'create MANIFEST file' );
68
69my @list = read_manifest();
70is( @list, 2, 'check files in MANIFEST' );
71ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
72
73# after adding bar, the MANIFEST is out of date
74ok( add_file( 'bar' ), 'add another file' );
75ok( ! manicheck(), 'MANIFEST now out of sync' );
76
77# it reports that bar has been added and throws a warning
78($res, $warn) = catch_warning( \&filecheck );
79
80like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
81is( $res, 'bar', 'bar reported as new' );
82
83# now quiet the warning that bar was added and test again
39234879 84{ package ExtUtils::Manifest; use vars qw($Quiet); $Quiet = 1; }
0300da75 85($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
4940c443 86cmp_ok( $warn, ,'eq', '', 'disabled warnings' );
0300da75
MS
87
88# add a skip file with a rule to skip itself
89add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
90
91# this'll skip the new file
92($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
93like( $warn, qr/^Skipping MANIFEST\.SKIP/, 'got skipping warning' );
94
95# I'm not sure why this should be... shouldn't $missing be the only one?
96my ($found, $missing );
97catch_warning( sub {
98 ( $found, $missing ) = ExtUtils::Manifest::skipcheck()
99});
100
101# nothing new should be found, bar should be skipped
102is( @$found, 0, 'no output here' );
103is( join( ' ', @$missing ), 'bar', 'listed skipped files' );
104
105is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
106
107# add a subdirectory and a file there that should be found
108ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
109my $quux = File::Spec->catfile( 'moretest', 'quux' );
8dee7ff3 110$quux =~ s#\\#/#g;
349e1be1 111$quux = VMS::Filespec::unixify($quux) if $^O eq 'VMS';
0300da75
MS
112add_file( $quux, 'quux' );
113ok( exists( ExtUtils::Manifest::manifind()->{$quux} ), "manifind found $quux" );
114
115# only MANIFEST and foo are in the manifest
116my $files = maniread();
117is( keys %$files, 2, 'two files found' );
6bcc4512 118is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST', 'both files found' );
0300da75
MS
119
120# poison the manifest, and add a comment that should be reported
121add_file( 'MANIFEST', 'none #none' );
122is( ExtUtils::Manifest::maniread()->{none}, '#none', 'maniread found comment' );
123
124ok( mkdir( 'copy', 0777 ), 'made copy directory' );
125
126$files = maniread();
127eval { (undef, $warn) = catch_warning( sub {
128 manicopy( $files, 'copy', 'cp' ) })
129};
130
131# a newline comes through, so get rid of it
132chomp($warn);
133
134# the copy should have given one warning and one error
135is($warn, 'Skipping MANIFEST.SKIP', 'warned about MANIFEST.SKIP' );
86e8f854 136like( $@, qr/^Can't read none: /,
0300da75
MS
137 'carped about none' );
138
139# tell ExtUtils::Manifest to use a different file
39234879
MS
140{ package ExtUtils::Manifest;
141 use vars qw($MANIFEST);
142 $MANIFEST = 'albatross';
143}
0300da75
MS
144
145($res, $warn) = catch_warning( \&mkmanifest );
146like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
147
148# add the new file to the list of files to be deleted
149push @files, 'albatross';
150
151END {
152 # the arrays are evaluated in scalar context
153 is( unlink( @files ), @files, 'remove all added files' );
154 remove_dir( 'moretest', 'copy' );
155
156 # now get rid of the parent directory
157 ok( chdir( $cwd ), 'return to parent directory' );
349e1be1 158 unlink('mantest/MANIFEST');
0300da75
MS
159 remove_dir( 'mantest' );
160}
349e1be1 161