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