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
CommitLineData
bb4e9162 1#!/usr/bin/perl -w
2
3use strict;
4use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5use MBTest;
738349a8 6
bb4e9162 7use Module::Build;
8use Module::Build::ConfigData;
9
10my $manpage_support = Module::Build::ConfigData->feature('manpage_support');
11my $HTML_support = Module::Build::ConfigData->feature('HTML_support');
12
bb4e9162 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.";
40008441 23 } elsif ( $^O eq 'VMS' ) {
24 plan skip_all => "Needs porting work on VMS";
bb4e9162 25 } else {
738349a8 26 plan tests => 13;
bb4e9162 27 }
28}
738349a8 29ensure_blib('Module::Build');
bb4e9162 30
31
7a827510 32my $tmp = MBTest->tmpdir;
bb4e9162 33
34
35use DistGen;
36my $dist = DistGen->new( dir => $tmp, xs => 1 );
37$dist->add_file( 'hello', <<'---' );
38#!perl -w
39print "Hello, World!\n";
40__END__
41
42=pod
43
44=head1 NAME
45
46hello
47
48=head1 DESCRIPTION
49
50Says "Hello"
51
52=cut
53---
7a827510 54$dist->change_build_pl
55({
56 module_name => $dist->name,
bb4e9162 57 license => 'perl',
58 scripts => [ 'hello' ],
7a827510 59});
bb4e9162 60$dist->regen;
61
738349a8 62$dist->chdir_in;
bb4e9162 63
64use File::Spec::Functions qw(catdir);
65
66use Module::Build;
67my @installstyle = qw(lib perl5);
68my $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;
89my $ppd = slurp($dist_filename . '.ppd');
90
91my $perl_version = Module::Build::PPMMaker->_ppd_version($mb->perl_version);
92my $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.
97is $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');
114is $@, '';
115
116my $tar = Archive::Tar->new;
117
118my $tarfile = $mb->ppm_name . '.tar.gz';
119$tar->read( $tarfile, 1 );
120
121my $files = { map { $_ => 1 } $tar->list_files };
122
7253302f 123my $fname = 'Simple';
124$fname = DynaLoader::mod2fname([$fname]) if defined &DynaLoader::mod2fname;
125exists_ok($files, "blib/arch/auto/Simple/$fname." . $mb->config('dlext'));
bb4e9162 126exists_ok($files, 'blib/lib/Simple.pm');
127exists_ok($files, 'blib/script/hello');
128
129SKIP: {
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
136SKIP: {
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;
144undef( $tar );
145
146$mb->dispatch('realclean');
147$dist->clean;
148
149
150SKIP: {
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
bb4e9162 185$dist->remove;
186
bb4e9162 187
188########################################
189
190sub 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.
199sub 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.
212sub html_reset {
213 return (
214 installhtmldir => '',
215 installhtml1dir => '',
216 installhtml3dir => '',
217 installsitehtml1dir => '',
218 installsitehtml3dir => '',
219 installvendorhtml1dir => '',
220 installvendorhtml3dir => '',
221 );
222}
223