Commit | Line | Data |
---|---|---|
39234879 | 1 | #!/usr/bin/perl |
0300da75 MS |
2 | |
3 | BEGIN { | |
39234879 MS |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't' if -d 't'; | |
6 | unshift @INC, '../lib'; | |
7 | } | |
0300da75 | 8 | } |
39234879 | 9 | chdir 't'; |
0300da75 MS |
10 | |
11 | # these files help the test run | |
12 | use Test::More tests => 31; | |
13 | use Cwd; | |
14 | ||
15 | # these files are needed for the module itself | |
16 | use File::Spec; | |
17 | use File::Path; | |
18 | use Carp::Heavy; | |
19 | ||
20 | # keep track of everything added so it can all be deleted | |
21 | my @files; | |
22 | sub 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 | ||
30 | sub read_manifest { | |
31 | open( my $M, 'MANIFEST' ) or return; | |
32 | chomp( my @files = <$M> ); | |
33 | return @files; | |
34 | } | |
35 | ||
36 | sub catch_warning { | |
37 | my $warn; | |
38 | local $SIG{__WARN__} = sub { $warn .= $_[0] }; | |
39 | return join('', $_[0]->() ), $warn; | |
40 | } | |
41 | ||
42 | sub remove_dir { | |
43 | ok( rmdir( $_ ), "remove $_ directory" ) for @_; | |
44 | } | |
45 | ||
46 | # use module, import functions | |
39234879 MS |
47 | BEGIN { use_ok( 'ExtUtils::Manifest', |
48 | qw( mkmanifest manicheck filecheck fullcheck maniread manicopy) ); } | |
0300da75 MS |
49 | |
50 | my $cwd = Cwd::getcwd(); | |
51 | ||
52 | # Just in case any old files were lying around. | |
53 | rmtree('mantest'); | |
54 | ||
55 | ok( mkdir( 'mantest', 0777 ), 'make mantest directory' ); | |
56 | ok( chdir( 'mantest' ), 'chdir() to mantest' ); | |
57 | ok( add_file('foo'), 'add a temporary file' ); | |
58 | ||
59 | # there shouldn't be a MANIFEST there | |
60 | my ($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); | |
63 | is( $warn, "Added to MANIFEST: foo|Added to MANIFEST: MANIFEST|", | |
64 | "mkmanifest() displayed it's additions" ); | |
0300da75 MS |
65 | |
66 | # and now you see it | |
67 | ok( -e 'MANIFEST', 'create MANIFEST file' ); | |
68 | ||
69 | my @list = read_manifest(); | |
70 | is( @list, 2, 'check files in MANIFEST' ); | |
71 | ok( ! ExtUtils::Manifest::filecheck(), 'no additional files in directory' ); | |
72 | ||
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' ); | |
76 | ||
77 | # it reports that bar has been added and throws a warning | |
78 | ($res, $warn) = catch_warning( \&filecheck ); | |
79 | ||
80 | like( $warn, qr/^Not in MANIFEST: bar/, 'warning that bar has been added' ); | |
81 | is( $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 | 86 | cmp_ok( $warn, ,'eq', '', 'disabled warnings' ); |
0300da75 MS |
87 | |
88 | # add a skip file with a rule to skip itself | |
89 | add_file( 'MANIFEST.SKIP', "baz\n.SKIP" ); | |
90 | ||
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' ); | |
94 | ||
95 | # I'm not sure why this should be... shouldn't $missing be the only one? | |
96 | my ($found, $missing ); | |
97 | catch_warning( sub { | |
98 | ( $found, $missing ) = ExtUtils::Manifest::skipcheck() | |
99 | }); | |
100 | ||
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' ); | |
104 | ||
105 | is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' ); | |
106 | ||
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' ); | |
8dee7ff3 | 110 | $quux =~ s#\\#/#g; |
349e1be1 | 111 | $quux = VMS::Filespec::unixify($quux) if $^O eq 'VMS'; |
0300da75 MS |
112 | add_file( $quux, 'quux' ); |
113 | ok( exists( ExtUtils::Manifest::manifind()->{$quux} ), "manifind found $quux" ); | |
114 | ||
115 | # only MANIFEST and foo are in the manifest | |
116 | my $files = maniread(); | |
117 | is( keys %$files, 2, 'two files found' ); | |
6bcc4512 | 118 | is( 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 | |
121 | add_file( 'MANIFEST', 'none #none' ); | |
122 | is( ExtUtils::Manifest::maniread()->{none}, '#none', 'maniread found comment' ); | |
123 | ||
124 | ok( mkdir( 'copy', 0777 ), 'made copy directory' ); | |
125 | ||
126 | $files = maniread(); | |
127 | eval { (undef, $warn) = catch_warning( sub { | |
128 | manicopy( $files, 'copy', 'cp' ) }) | |
129 | }; | |
130 | ||
131 | # a newline comes through, so get rid of it | |
132 | chomp($warn); | |
133 | ||
134 | # the copy should have given one warning and one error | |
135 | is($warn, 'Skipping MANIFEST.SKIP', 'warned about MANIFEST.SKIP' ); | |
86e8f854 | 136 | like( $@, 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 ); | |
146 | like( $warn, qr/Added to albatross: /, 'using a new manifest file' ); | |
147 | ||
148 | # add the new file to the list of files to be deleted | |
149 | push @files, 'albatross'; | |
150 | ||
151 | END { | |
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 |