Add ExtUtils::Miniperl to the list of core modules for all versions >= 5.00504
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / ppm.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest;
6
7 use Module::Build;
8 use Module::Build::ConfigData;
9
10 my $manpage_support = Module::Build::ConfigData->feature('manpage_support');
11 my $HTML_support = Module::Build::ConfigData->feature('HTML_support');
12
13 {
14   my ($have_c_compiler, $C_support_feature) = check_compiler();
15   if (! $C_support_feature) {
16     plan skip_all => 'C_support not enabled';
17   } elsif ( ! $have_c_compiler ) {
18     plan skip_all => 'C_support enabled, but no compiler found';
19   } elsif ( ! eval {require Archive::Tar} ) {
20     plan skip_all => "Archive::Tar not installed to read archives.";
21   } elsif ( ! eval {IO::Zlib->VERSION(1.01)} ) {
22     plan skip_all => "IO::Zlib 1.01 required to read compressed archives.";
23   } elsif ( $^O eq 'VMS' ) {
24     plan skip_all => "Needs porting work on VMS";
25   } else {
26     plan tests => 13;
27   }
28 }
29 ensure_blib('Module::Build');
30
31
32 my $tmp = MBTest->tmpdir;
33
34
35 use DistGen;
36 my $dist = DistGen->new( dir => $tmp, xs => 1 );
37 $dist->add_file( 'hello', <<'---' );
38 #!perl -w
39 print "Hello, World!\n";
40 __END__
41
42 =pod
43
44 =head1 NAME
45
46 hello
47
48 =head1 DESCRIPTION
49
50 Says "Hello"
51
52 =cut
53 ---
54 $dist->change_build_pl
55 ({
56   module_name => $dist->name,
57   license     => 'perl',
58   scripts     => [ 'hello' ],
59 });
60 $dist->regen;
61
62 $dist->chdir_in;
63
64 use File::Spec::Functions qw(catdir);
65
66 use Module::Build;
67 my @installstyle = qw(lib perl5);
68 my $mb = Module::Build->new_from_context(
69   verbose => 0,
70   quiet   => 1,
71
72   installdirs => 'site',
73   config => {
74     manpage_reset(), html_reset(),
75     ( $manpage_support ?
76       ( installsiteman1dir  => catdir($tmp, 'site', 'man', 'man1'),
77         installsiteman3dir  => catdir($tmp, 'site', 'man', 'man3') ) : () ),
78     ( $HTML_support ?
79       ( installsitehtml1dir => catdir($tmp, 'site', 'html'),
80         installsitehtml3dir => catdir($tmp, 'site', 'html') ) : () ),
81   },
82 );
83
84
85
86 $mb->dispatch('ppd', args => {codebase => '/path/to/codebase-xs'});
87
88 (my $dist_filename = $dist->name) =~ s/::/-/g;
89 my $ppd = slurp($dist_filename . '.ppd');
90
91 my $perl_version = Module::Build::PPMMaker->_ppd_version($mb->perl_version);
92 my $varchname = Module::Build::PPMMaker->_varchname($mb->config);
93
94 # This test is quite a hack since with XML you don't really want to
95 # do a strict string comparison, but absent an XML parser it's the
96 # best we can do.
97 is $ppd, <<"---";
98 <SOFTPKG NAME="$dist_filename" VERSION="0,01,0,0">
99     <TITLE>@{[$dist->name]}</TITLE>
100     <ABSTRACT>Perl extension for blah blah blah</ABSTRACT>
101     <AUTHOR>A. U. Thor, a.u.thor\@a.galaxy.far.far.away</AUTHOR>
102     <IMPLEMENTATION>
103         <PERLCORE VERSION="$perl_version" />
104         <OS NAME="$^O" />
105         <ARCHITECTURE NAME="$varchname" />
106         <CODEBASE HREF="/path/to/codebase-xs" />
107     </IMPLEMENTATION>
108 </SOFTPKG>
109 ---
110
111
112
113 $mb->dispatch('ppmdist');
114 is $@, '';
115
116 my $tar = Archive::Tar->new;
117
118 my $tarfile = $mb->ppm_name . '.tar.gz';
119 $tar->read( $tarfile, 1 );
120
121 my $files = { map { $_ => 1 } $tar->list_files };
122
123 my $fname = 'Simple';
124 $fname = DynaLoader::mod2fname([$fname]) if defined &DynaLoader::mod2fname;
125 exists_ok($files, "blib/arch/auto/Simple/$fname." . $mb->config('dlext'));
126 exists_ok($files, 'blib/lib/Simple.pm');
127 exists_ok($files, 'blib/script/hello');
128
129 SKIP: {
130   skip( "manpage_support not enabled.", 2 ) unless $manpage_support;
131
132   exists_ok($files, 'blib/man3/Simple.' . $mb->config('man3ext'));
133   exists_ok($files, 'blib/man1/hello.' . $mb->config('man1ext'));
134 }
135
136 SKIP: {
137   skip( "HTML_support not enabled.", 2 ) unless $HTML_support;
138
139   exists_ok($files, 'blib/html/site/lib/Simple.html');
140   exists_ok($files, 'blib/html/bin/hello.html');
141 }
142
143 $tar->clear;
144 undef( $tar );
145
146 $mb->dispatch('realclean');
147 $dist->clean;
148
149
150 SKIP: {
151   skip( "HTML_support not enabled.", 3 ) unless $HTML_support;
152
153   # Make sure html documents are generated for the ppm distro even when
154   # they would not be built during a normal build.
155   $mb = Module::Build->new_from_context(
156     verbose => 0,
157     quiet   => 1,
158
159     installdirs => 'site',
160     config => {
161       html_reset(),
162       installsiteman1dir  => catdir($tmp, 'site', 'man', 'man1'),
163       installsiteman3dir  => catdir($tmp, 'site', 'man', 'man3'),
164     },
165   );
166
167   $mb->dispatch('ppmdist');
168   is $@, '';
169
170   $tar = Archive::Tar->new;
171   $tar->read( $tarfile, 1 );
172
173   $files = {map { $_ => 1 } $tar->list_files};
174
175   exists_ok($files, 'blib/html/site/lib/Simple.html');
176   exists_ok($files, 'blib/html/bin/hello.html');
177
178   $tar->clear;
179
180   $mb->dispatch('realclean');
181   $dist->clean;
182 }
183
184
185 $dist->remove;
186
187
188 ########################################
189
190 sub exists_ok {
191   my $files = shift;
192   my $file  = shift;
193   local $Test::Builder::Level = $Test::Builder::Level + 1;
194   ok exists( $files->{$file} ) && $files->{$file}, $file;
195 }
196
197 # A hash of all Config.pm settings related to installing
198 # manpages with values set to an empty string.
199 sub manpage_reset {
200   return (
201     installman1dir => '',
202     installman3dir => '',
203     installsiteman1dir => '',
204     installsiteman3dir => '',
205     installvendorman1dir => '',
206     installvendorman3dir => '',
207   );
208 }
209
210 # A hash of all Config.pm settings related to installing
211 # html documents with values set to an empty string.
212 sub html_reset {
213   return (
214     installhtmldir => '',
215     installhtml1dir => '',
216     installhtml3dir => '',
217     installsitehtml1dir => '',
218     installsitehtml3dir => '',
219     installvendorhtml1dir => '',
220     installvendorhtml3dir => '',
221   );
222 }
223