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