5 unshift @INC, '../lib';
8 # these files help the test run
9 use Test::More tests => 31;
12 # these files are needed for the module itself
17 # keep track of everything added so it can all be deleted
20 my ($file, $data) = @_;
22 open( my $T, '>', $file) or return;
28 open( my $M, 'MANIFEST' ) or return;
29 chomp( my @files = <$M> );
35 local $SIG{__WARN__} = sub { $warn .= $_[0] };
36 return join('', $_[0]->() ), $warn;
40 ok( rmdir( $_ ), "remove $_ directory" ) for @_;
43 # use module, import functions
44 use_ok( 'ExtUtils::Manifest',
45 qw( mkmanifest manicheck filecheck fullcheck maniread manicopy) );
47 my $cwd = Cwd::getcwd();
49 # Just in case any old files were lying around.
52 ok( mkdir( 'mantest', 0777 ), 'make mantest directory' );
53 ok( chdir( 'mantest' ), 'chdir() to mantest' );
54 ok( add_file('foo'), 'add a temporary file' );
56 # there shouldn't be a MANIFEST there
57 my ($res, $warn) = catch_warning( \&mkmanifest );
58 is( $warn, <<ADDING, "mkmanifest() displayed it's additions" );
59 Added to MANIFEST: MANIFEST
60 Added to MANIFEST: foo
64 ok( -e 'MANIFEST', 'create MANIFEST file' );
66 my @list = read_manifest();
67 is( @list, 2, 'check files in MANIFEST' );
68 ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' );
70 # after adding bar, the MANIFEST is out of date
71 ok( add_file( 'bar' ), 'add another file' );
72 ok( ! manicheck(), 'MANIFEST now out of sync' );
74 # it reports that bar has been added and throws a warning
75 ($res, $warn) = catch_warning( \&filecheck );
77 like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' );
78 is( $res, 'bar', 'bar reported as new' );
80 # now quiet the warning that bar was added and test again
81 use vars qw($ExtUtils::Manifest::Quiet);
82 $ExtUtils::Manifest::Quiet = 1;
83 ($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
84 is( $warn, '', 'disabled warnings' );
86 # add a skip file with a rule to skip itself
87 add_file( 'MANIFEST.SKIP', "baz\n.SKIP" );
89 # this'll skip the new file
90 ($res, $warn) = catch_warning( \&ExtUtils::Manifest::skipcheck );
91 like( $warn, qr/^Skipping MANIFEST\.SKIP/, 'got skipping warning' );
93 # I'm not sure why this should be... shouldn't $missing be the only one?
94 my ($found, $missing );
96 ( $found, $missing ) = ExtUtils::Manifest::skipcheck()
99 # nothing new should be found, bar should be skipped
100 is( @$found, 0, 'no output here' );
101 is( join( ' ', @$missing ), 'bar', 'listed skipped files' );
103 is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' );
105 # add a subdirectory and a file there that should be found
106 ok( mkdir( 'moretest', 0777 ), 'created moretest directory' );
107 my $quux = File::Spec->catfile( 'moretest', 'quux' );
109 $quux = VMS::Filespec::unixify($quux) if $^O eq 'VMS';
110 add_file( $quux, 'quux' );
111 ok( exists( ExtUtils::Manifest::manifind()->{$quux} ), "manifind found $quux" );
113 # only MANIFEST and foo are in the manifest
114 my $files = maniread();
115 is( keys %$files, 2, 'two files found' );
116 is( join(' ', sort keys %$files), 'MANIFEST foo', 'both files found' );
118 # poison the manifest, and add a comment that should be reported
119 add_file( 'MANIFEST', 'none #none' );
120 is( ExtUtils::Manifest::maniread()->{none}, '#none', 'maniread found comment' );
122 ok( mkdir( 'copy', 0777 ), 'made copy directory' );
125 eval { (undef, $warn) = catch_warning( sub {
126 manicopy( $files, 'copy', 'cp' ) })
129 # a newline comes through, so get rid of it
132 # the copy should have given one warning and one error
133 is($warn, 'Skipping MANIFEST.SKIP', 'warned about MANIFEST.SKIP' );
134 like( $@, qr/^Can't read none: /,
135 'carped about none' );
137 # tell ExtUtils::Manifest to use a different file
138 use vars qw($ExtUtils::Manifest::MANIFEST);
139 $ExtUtils::Manifest::MANIFEST = 'albatross';
141 ($res, $warn) = catch_warning( \&mkmanifest );
142 like( $warn, qr/Added to albatross: /, 'using a new manifest file' );
144 # add the new file to the list of files to be deleted
145 push @files, 'albatross';
148 # the arrays are evaluated in scalar context
149 is( unlink( @files ), @files, 'remove all added files' );
150 remove_dir( 'moretest', 'copy' );
152 # now get rid of the parent directory
153 ok( chdir( $cwd ), 'return to parent directory' );
154 unlink('mantest/MANIFEST');
155 remove_dir( 'mantest' );