4 if( $ENV{PERL_CORE} ) {
6 unshift @INC, '../lib';
11 # these files help the test run
12 use Test::More tests => 31;
15 # these files are needed for the module itself
20 # keep track of everything added so it can all be deleted
23 my ($file, $data) = @_;
25 open( my $T, '>', $file) or return;
31 open( my $M, 'MANIFEST' ) or return;
32 chomp( my @files = <$M> );
38 local $SIG{__WARN__} = sub { $warn .= $_[0] };
39 return join('', $_[0]->() ), $warn;
43 ok( rmdir( $_ ), "remove $_ directory" ) for @_;
46 # use module, import functions
47 BEGIN { use_ok( 'ExtUtils::Manifest',
48 qw( mkmanifest manicheck filecheck fullcheck maniread manicopy) ); }
50 my $cwd = Cwd::getcwd();
52 # Just in case any old files were lying around.
55 ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
56 ok( chdir( 'mantest' ), 'chdir() to mantest' );
57 ok( add_file('foo'), 'add a temporary file' );
59 # there shouldn't be a MANIFEST there
60 my ($res, $warn) = catch_warning( \&mkmanifest );
62 $warn = join("", map { "$_|" } sort { lc $a cmp lc $b } split /\r?\n/, $warn);
63 is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|",
64 "mkmanifest() displayed it's additions" );
67 ok( -e 'MANIFEST', 'create MANIFEST file' );
69 my @list = read_manifest();
70 is( @list, 2, 'check files in MANIFEST' );
71 ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
73 # after adding bar, the MANIFEST is out of date
74 ok( add_file( 'bar' ), 'add another file' );
75 ok( ! manicheck(), 'MANIFEST now out of sync' );
77 # it reports that bar has been added and throws a warning
78 ($res, $warn) = catch_warning( \&filecheck );
80 like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
81 is( $res, 'bar', 'bar reported as new' );
83 # now quiet the warning that bar was added and test again
84 { package ExtUtils::Manifest; use vars qw($Quiet); $Quiet = 1; }
85 ($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
86 cmp_ok( $warn, ,'eq', '', 'disabled warnings' );
88 # add a skip file with a rule to skip itself
89 add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
91 # this'll skip the new file
92 ($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
93 like( $warn, qr/^Skipping MANIFEST\.SKIP/, 'got skipping warning' );
95 # I'm not sure why this should be... shouldn't $missing be the only one?
96 my ($found, $missing );
98 ( $found, $missing ) = ExtUtils::Manifest::skipcheck()
101 # nothing new should be found, bar should be skipped
102 is( @$found, 0, 'no output here' );
103 is( join( ' ', @$missing ), 'bar', 'listed skipped files' );
105 is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
107 # add a subdirectory and a file there that should be found
108 ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
109 my $quux = File::Spec->catfile( 'moretest', 'quux' );
111 $quux = VMS::Filespec::unixify($quux) if $^O eq 'VMS';
112 add_file( $quux, 'quux' );
113 ok( exists( ExtUtils::Manifest::manifind()->{$quux} ), "manifind found $quux" );
115 # only MANIFEST and foo are in the manifest
116 my $files = maniread();
117 is( keys %$files, 2, 'two files found' );
118 is( join(' ', sort { lc($a) cmp lc($b) } keys %$files), 'foo MANIFEST', 'both files found' );
120 # poison the manifest, and add a comment that should be reported
121 add_file( 'MANIFEST', 'none #none' );
122 is( ExtUtils::Manifest::maniread()->{none}, '#none', 'maniread found comment' );
124 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
127 eval { (undef, $warn) = catch_warning( sub {
128 manicopy( $files, 'copy', 'cp' ) })
131 # a newline comes through, so get rid of it
134 # the copy should have given one warning and one error
135 is($warn, 'Skipping MANIFEST.SKIP', 'warned about MANIFEST.SKIP' );
136 like( $@, qr/^Can't read none: /,
137 'carped about none' );
139 # tell ExtUtils::Manifest to use a different file
140 { package ExtUtils::Manifest;
141 use vars qw($MANIFEST);
142 $MANIFEST = 'albatross';
145 ($res, $warn) = catch_warning( \&mkmanifest );
146 like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
148 # add the new file to the list of files to be deleted
149 push @files, 'albatross';
152 # the arrays are evaluated in scalar context
153 is( unlink( @files ), @files, 'remove all added files' );
154 remove_dir( 'moretest', 'copy' );
156 # now get rid of the parent directory
157 ok( chdir( $cwd ), 'return to parent directory' );
158 unlink('mantest/MANIFEST');
159 remove_dir( 'mantest' );