summaryrefslogtreecommitdiff
path: root/lib/ExtUtils/Manifest.t
blob: 2492e2af43cbf540d5f4be86509852760bb48389 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!./perl 

BEGIN {
    chdir 't' if -d 't';
    unshift @INC, '../lib';
}

# these files help the test run
use Test::More tests => 31;
use Cwd;

# these files are needed for the module itself
use File::Spec;
use File::Path;
use Carp::Heavy;

# keep track of everything added so it can all be deleted
my @files;
sub add_file {
	my ($file, $data) = @_;
	$data ||= 'foo';
	open( my $T, '>', $file) or return;
	print $T $data;
	push @files, $file;
}

sub read_manifest {
	open( my $M, 'MANIFEST' ) or return;
	chomp( my @files = <$M> );
	return @files;
}

sub catch_warning {
	my $warn;
	local $SIG{__WARN__} = sub { $warn .= $_[0] };
	return join('', $_[0]->() ), $warn;
}

sub remove_dir {
	ok( rmdir( $_ ), "remove $_ directory" ) for @_;
}

# use module, import functions
use_ok( 'ExtUtils::Manifest', 
	qw( mkmanifest manicheck filecheck fullcheck maniread manicopy) );

my $cwd = Cwd::getcwd();

# Just in case any old files were lying around.
rmtree('mantest');

ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
ok( chdir( 'mantest' ), 'chdir() to mantest' );
ok( add_file('foo'), 'add a temporary file' );

# there shouldn't be a MANIFEST there
my ($res, $warn) = catch_warning( \&mkmanifest ); 
is( $warn, <<ADDING, "mkmanifest() displayed it's additions" );
Added to MANIFEST: MANIFEST
Added to MANIFEST: foo
ADDING

# and now you see it
ok( -e 'MANIFEST', 'create MANIFEST file' );

my @list = read_manifest();
is( @list, 2, 'check files in MANIFEST' );
ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );

# after adding bar, the MANIFEST is out of date
ok( add_file( 'bar' ), 'add another file' );
ok( ! manicheck(), 'MANIFEST now out of sync' );

# it reports that bar has been added and throws a warning
($res, $warn) = catch_warning( \&filecheck );

like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
is( $res, 'bar', 'bar reported as new' );

# now quiet the warning that bar was added and test again
use vars qw($ExtUtils::Manifest::Quiet);
$ExtUtils::Manifest::Quiet = 1;
($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
is( $warn, '', 'disabled warnings' );

# add a skip file with a rule to skip itself
add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );

# this'll skip the new file
($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
like( $warn, qr/^Skipping MANIFEST\.SKIP/, 'got skipping warning' );

# I'm not sure why this should be... shouldn't $missing be the only one?
my ($found, $missing );
catch_warning( sub {
	( $found, $missing ) = ExtUtils::Manifest::skipcheck()
});

# nothing new should be found, bar should be skipped
is( @$found, 0, 'no output here' );
is( join( ' ', @$missing ), 'bar', 'listed skipped files' );

is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );

# add a subdirectory and a file there that should be found
ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
my $quux = File::Spec->catfile( 'moretest', 'quux' );
$quux =~ s#\\#/#g;
$quux = VMS::Filespec::unixify($quux) if $^O eq 'VMS';
add_file( $quux, 'quux' );
ok( exists( ExtUtils::Manifest::manifind()->{$quux} ), "manifind found $quux" );

# only MANIFEST and foo are in the manifest
my $files = maniread();
is( keys %$files, 2, 'two files found' );
is( join(' ', sort keys %$files), 'MANIFEST foo', 'both files found' );

# poison the manifest, and add a comment that should be reported
add_file( 'MANIFEST', 'none #none' );
is( ExtUtils::Manifest::maniread()->{none}, '#none', 'maniread found comment' );

ok( mkdir( 'copy', 0777 ), 'made copy directory' );

$files = maniread();
eval { (undef, $warn) = catch_warning( sub {
		manicopy( $files, 'copy', 'cp' ) }) 
};

# a newline comes through, so get rid of it
chomp($warn);

# the copy should have given one warning and one error
is($warn, 'Skipping MANIFEST.SKIP', 'warned about MANIFEST.SKIP' );
like( $@, qr/^Can't read none: /, 
                                               'carped about none' );

# tell ExtUtils::Manifest to use a different file
use vars qw($ExtUtils::Manifest::MANIFEST);
$ExtUtils::Manifest::MANIFEST = 'albatross';

($res, $warn) = catch_warning( \&mkmanifest );
like( $warn, qr/Added to albatross: /, 'using a new manifest file' );

# add the new file to the list of files to be deleted
push @files, 'albatross';

END {
	# the arrays are evaluated in scalar context
	is( unlink( @files ), @files, 'remove all added files' );
	remove_dir( 'moretest', 'copy' );

	# now get rid of the parent directory
	ok( chdir( $cwd ), 'return to parent directory' );
	unlink('mantest/MANIFEST');
	remove_dir( 'mantest' );
}